This commit is contained in:
2026-06-15 16:42:28 +03:30
commit 068930c7bd
158 changed files with 5330 additions and 0 deletions
+208
View File
@@ -0,0 +1,208 @@
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 '../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: SafeArea(
child: BlocBuilder<WalletCubit, WalletState>(
builder: (context, state) {
return Column(
children: [
_TopBar(wallet: state.wallet),
Expanded(
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text('سلطان حکم',
style: TextStyle(
fontSize: 40,
fontWeight: FontWeight.bold,
color: AppColors.gold)),
const SizedBox(height: 48),
_MenuButton(
label: 'بازی',
icon: Icons.style,
color: const Color(0xFF8E1B5B),
onTap: () async {
await context.push('/game/tiers');
if (context.mounted) {
context.read<WalletCubit>().load();
}
},
),
const SizedBox(height: 16),
_MenuButton(
label: 'فروشگاه',
icon: Icons.storefront,
color: const Color(0xFF4A148C),
onTap: () async {
await context.push('/shop');
if (context.mounted) {
context.read<WalletCubit>().load();
}
},
),
const SizedBox(height: 16),
_MenuButton(
label: 'سکه روزانه',
icon: Icons.monetization_on,
color: AppColors.green,
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> _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;
const _TopBar({this.wallet});
@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(
color: AppColors.bgDark,
borderRadius: BorderRadius.circular(14),
border: Border.all(color: AppColors.goldDark),
),
child: Row(
children: [
const CircleAvatar(
backgroundColor: AppColors.panel,
child: Icon(Icons.person, color: AppColors.gold),
),
const SizedBox(width: 10),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('سطح ${w?.level ?? '-'}',
style: const TextStyle(color: AppColors.gold)),
if (w != null)
SizedBox(
width: 90,
child: LinearProgressIndicator(
value: w.xpForNext == 0 ? 0 : w.xpIntoLevel / w.xpForNext,
backgroundColor: Colors.white12,
color: AppColors.gold,
minHeight: 5,
),
),
],
),
const Spacer(),
_Chip(icon: Icons.confirmation_number, value: w?.tickets ?? 0),
const SizedBox(width: 8),
_Chip(icon: Icons.monetization_on, value: w?.coins ?? 0),
],
),
);
}
}
class _Chip extends StatelessWidget {
final IconData icon;
final int value;
const _Chip({required this.icon, required this.value});
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
decoration: BoxDecoration(
color: AppColors.panel,
borderRadius: BorderRadius.circular(20),
border: Border.all(color: AppColors.goldDark),
),
child: Row(
children: [
Icon(icon, color: AppColors.gold, size: 18),
const SizedBox(width: 6),
Text('$value', style: const TextStyle(color: AppColors.text)),
],
),
);
}
}
class _MenuButton extends StatelessWidget {
final String label;
final IconData icon;
final Color color;
final VoidCallback onTap;
const _MenuButton({
required this.label,
required this.icon,
required this.color,
required this.onTap,
});
@override
Widget build(BuildContext context) {
return SizedBox(
width: 280,
child: ElevatedButton.icon(
style: ElevatedButton.styleFrom(backgroundColor: color),
onPressed: onTap,
icon: Icon(icon, color: AppColors.gold),
label: Text(label),
),
);
}
}
+42
View File
@@ -0,0 +1,42 @@
import 'package:equatable/equatable.dart';
/// وضعیت اقتصادی کاربر (پاسخ GET /api/wallet).
class Wallet extends Equatable {
final int coins;
final int tickets;
final int xp;
final int trophies;
final int level;
final int xpIntoLevel;
final int xpForNext;
final bool vip;
final String selectedCard;
const Wallet({
required this.coins,
required this.tickets,
required this.xp,
required this.trophies,
required this.level,
required this.xpIntoLevel,
required this.xpForNext,
required this.vip,
required this.selectedCard,
});
factory Wallet.fromJson(Map<String, dynamic> j) => Wallet(
coins: (j['coins'] ?? 0) as int,
tickets: (j['tickets'] ?? 0) as int,
xp: (j['xp'] ?? 0) as int,
trophies: (j['trophies'] ?? 0) as int,
level: (j['level'] ?? 1) as int,
xpIntoLevel: (j['xp_into_level'] ?? 0) as int,
xpForNext: (j['xp_for_next'] ?? 1) as int,
vip: (j['vip'] ?? false) as bool,
selectedCard: (j['selected_card'] ?? 'simple') as String,
);
@override
List<Object?> get props =>
[coins, tickets, xp, trophies, level, xpIntoLevel, xpForNext, vip, selectedCard];
}
+46
View File
@@ -0,0 +1,46 @@
import 'package:equatable/equatable.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../../core/network/api_client.dart';
import 'wallet.dart';
enum WalletStatus { initial, loading, loaded, error }
class WalletState extends Equatable {
final WalletStatus status;
final Wallet? wallet;
const WalletState({this.status = WalletStatus.initial, this.wallet});
@override
List<Object?> get props => [status, wallet];
}
class WalletCubit extends Cubit<WalletState> {
final ApiClient _api;
WalletCubit(this._api) : super(const WalletState());
Future<void> load() async {
emit(const WalletState(status: WalletStatus.loading));
try {
final res = await _api.dio.get('/wallet');
emit(WalletState(
status: WalletStatus.loaded,
wallet: Wallet.fromJson(Map<String, dynamic>.from(res.data)),
));
} catch (_) {
emit(const WalletState(status: WalletStatus.error));
}
}
/// دریافت سکه روزانه و سپس به‌روزرسانی کیف‌پول.
Future<int?> claimDaily() async {
try {
final res = await _api.dio.post('/rewards/daily');
await load();
return (res.data['amount'] ?? 0) as int;
} catch (_) {
return null;
}
}
}