Files
front-hokm/lib/features/lobby/lobby_screen.dart
T
2026-06-17 00:19:44 +03:30

193 lines
6.8 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import '../../core/theme/app_theme.dart';
import '../../core/widgets/game_ui.dart';
import '../auth/auth_cubit.dart';
import 'wallet.dart';
import 'wallet_cubit.dart';
/// لابی اصلی: کیف‌پول، دکمه بازی، فروشگاه، سکه روزانه (ظاهرِ بازی‌گونه).
class LobbyScreen extends StatefulWidget {
const LobbyScreen({super.key});
@override
State<LobbyScreen> createState() => _LobbyScreenState();
}
class _LobbyScreenState extends State<LobbyScreen> {
@override
void initState() {
super.initState();
context.read<WalletCubit>().load();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: GameBackground(
child: BlocBuilder<WalletCubit, WalletState>(
builder: (context, state) {
return Column(
children: [
_TopBar(wallet: state.wallet, onCoinTap: () => _openShop(context)),
Expanded(
child: Center(
child: SingleChildScrollView(
padding: const EdgeInsets.symmetric(horizontal: 28),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const GlowText('سلطان حکم', size: 44),
const SizedBox(height: 44),
GameButton(
label: 'بازی',
icon: Icons.style,
width: double.infinity,
colors: const [Color(0xFFC2185B), Color(0xFF6A0D38)],
onTap: () async {
await context.push('/game/tiers');
if (context.mounted) {
context.read<WalletCubit>().load();
}
},
),
const SizedBox(height: 16),
GameButton(
label: 'فروشگاه',
icon: Icons.storefront,
width: double.infinity,
colors: const [Color(0xFF7B1FA2), Color(0xFF3E0A57)],
onTap: () => _openShop(context),
),
const SizedBox(height: 16),
GameButton(
label: 'سکه روزانه',
icon: Icons.monetization_on,
width: double.infinity,
colors: const [Color(0xFF3FA34D), Color(0xFF1B5E20)],
onTap: () => _claimDaily(context),
),
],
),
),
),
),
TextButton.icon(
onPressed: () async {
await context.read<AuthCubit>().logout();
if (context.mounted) context.go('/login');
},
icon: const Icon(Icons.logout, color: Colors.white54),
label: const Text('خروج',
style: TextStyle(color: Colors.white54)),
),
const SizedBox(height: 8),
],
);
},
),
),
);
}
Future<void> _openShop(BuildContext context) async {
await context.push('/shop');
if (context.mounted) context.read<WalletCubit>().load();
}
Future<void> _claimDaily(BuildContext context) async {
final amount = await context.read<WalletCubit>().claimDaily();
if (!context.mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(amount != null
? 'سکه روزانه دریافت شد: +$amount'
: 'سکه روزانه را قبلاً امروز گرفته‌اید'),
),
);
}
}
class _TopBar extends StatelessWidget {
final Wallet? wallet;
final VoidCallback onCoinTap;
const _TopBar({this.wallet, required this.onCoinTap});
@override
Widget build(BuildContext context) {
final w = wallet;
return Container(
margin: const EdgeInsets.all(8),
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
decoration: BoxDecoration(
gradient: const LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [Color(0xFF3A0A12), Color(0xFF1A0106)],
),
borderRadius: BorderRadius.circular(16),
border: Border.all(color: AppColors.goldDark),
boxShadow: const [BoxShadow(color: Colors.black54, blurRadius: 8)],
),
child: Row(
children: [
Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(color: AppColors.gold, width: 2),
),
child: const CircleAvatar(
radius: 22,
backgroundColor: AppColors.panel,
child: Icon(Icons.person, color: AppColors.gold),
),
),
const SizedBox(width: 10),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Row(children: [
const Icon(Icons.star, color: AppColors.gold, size: 16),
const SizedBox(width: 4),
Text('سطح ${w?.level ?? '-'}',
style: const TextStyle(
color: AppColors.gold, fontWeight: FontWeight.bold)),
]),
const SizedBox(height: 4),
ClipRRect(
borderRadius: BorderRadius.circular(4),
child: SizedBox(
width: 96,
height: 7,
child: LinearProgressIndicator(
value: (w == null || w.xpForNext == 0)
? 0
: w.xpIntoLevel / w.xpForNext,
backgroundColor: Colors.white10,
valueColor: const AlwaysStoppedAnimation(AppColors.gold),
),
),
),
],
),
const Spacer(),
GestureDetector(
onTap: onCoinTap,
child: StatChip(
icon: Icons.confirmation_number, value: '${w?.tickets ?? 0}'),
),
const SizedBox(width: 8),
GestureDetector(
onTap: onCoinTap,
child: StatChip(
icon: Icons.monetization_on, value: '${w?.coins ?? 0}'),
),
],
),
);
}
}