feat: refactor code
This commit is contained in:
+64
-76
@@ -2,42 +2,33 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import 'core/network/api_client.dart';
|
||||
import 'core/network/ws_client.dart';
|
||||
import 'core/storage/token_storage.dart';
|
||||
import 'core/locator/locator.dart';
|
||||
import 'core/theme/app_theme.dart';
|
||||
import 'features/auth/auth_cubit.dart';
|
||||
import 'features/auth/auth_repository.dart';
|
||||
import 'features/auth/mobile_screen.dart';
|
||||
import 'features/auth/otp_screen.dart';
|
||||
import 'features/auth/profile_setup_screen.dart';
|
||||
import 'features/game/game_cubit.dart';
|
||||
import 'features/game/game_repository.dart';
|
||||
import 'features/game/game_screen.dart';
|
||||
import 'features/game/tier_list_screen.dart';
|
||||
import 'features/lobby/lobby_screen.dart';
|
||||
import 'features/lobby/wallet_cubit.dart';
|
||||
import 'features/private/private_entry_screen.dart';
|
||||
import 'features/private/private_table_screen.dart';
|
||||
import 'features/profile/profile_screen.dart';
|
||||
import 'features/shop/shop_cubit.dart';
|
||||
import 'features/shop/shop_repository.dart';
|
||||
import 'features/shop/shop_screen.dart';
|
||||
import 'features/shop/vip_screen.dart';
|
||||
import 'feature/auth/presentation/bloc/auth_bloc.dart';
|
||||
import 'feature/auth/presentation/screen/mobile_screen.dart';
|
||||
import 'feature/auth/presentation/screen/otp_screen.dart';
|
||||
import 'feature/auth/presentation/screen/profile_setup_screen.dart';
|
||||
import 'feature/game/presentation/bloc/game_bloc.dart';
|
||||
import 'feature/game/presentation/bloc/game_event.dart';
|
||||
import 'feature/game/presentation/bloc/private_info_bloc.dart';
|
||||
import 'feature/game/presentation/bloc/tier_bloc.dart';
|
||||
import 'feature/game/presentation/screen/game_screen.dart';
|
||||
import 'feature/game/presentation/screen/private_entry_screen.dart';
|
||||
import 'feature/game/presentation/screen/private_table_screen.dart';
|
||||
import 'feature/game/presentation/screen/tier_list_screen.dart';
|
||||
import 'feature/profile/presentation/bloc/profile_bloc.dart';
|
||||
import 'feature/profile/presentation/bloc/profile_event.dart';
|
||||
import 'feature/profile/presentation/screen/profile_screen.dart';
|
||||
import 'feature/shop/presentation/bloc/shop_bloc.dart';
|
||||
import 'feature/shop/presentation/bloc/shop_event.dart';
|
||||
import 'feature/shop/presentation/screen/shop_screen.dart';
|
||||
import 'feature/shop/presentation/screen/vip_screen.dart';
|
||||
import 'feature/wallet/presentation/bloc/wallet_bloc.dart';
|
||||
import 'feature/wallet/presentation/screen/lobby_screen.dart';
|
||||
|
||||
class HakemApp extends StatelessWidget {
|
||||
final ApiClient api;
|
||||
final AuthRepository authRepo;
|
||||
final TokenStorage tokenStorage;
|
||||
final bool loggedIn;
|
||||
|
||||
const HakemApp({
|
||||
super.key,
|
||||
required this.api,
|
||||
required this.authRepo,
|
||||
required this.tokenStorage,
|
||||
required this.loggedIn,
|
||||
});
|
||||
const HakemApp({super.key, required this.loggedIn});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -49,67 +40,65 @@ class HakemApp extends StatelessWidget {
|
||||
GoRoute(path: '/setup', builder: (_, __) => const ProfileSetupScreen()),
|
||||
GoRoute(path: '/lobby', builder: (_, __) => const LobbyScreen()),
|
||||
GoRoute(
|
||||
path: '/profile',
|
||||
builder: (_, __) => ProfileScreen(api: api)),
|
||||
GoRoute(
|
||||
path: '/private',
|
||||
builder: (_, __) => PrivateEntryScreen(api: api)),
|
||||
GoRoute(
|
||||
path: '/private/room',
|
||||
builder: (_, st) {
|
||||
final create = st.uri.queryParameters['create'] == '1';
|
||||
final joinCode = st.uri.queryParameters['join'];
|
||||
return FutureBuilder<String?>(
|
||||
future: tokenStorage.read(),
|
||||
builder: (context, snap) {
|
||||
if (!snap.hasData) {
|
||||
return const Scaffold(
|
||||
body: Center(child: CircularProgressIndicator()));
|
||||
}
|
||||
return PrivateTableScreen(
|
||||
token: snap.data!,
|
||||
create: create,
|
||||
joinCode: joinCode,
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
path: '/profile',
|
||||
builder: (_, __) => BlocProvider(
|
||||
create: (_) => locator<ProfileBloc>()..add(LoadProfileEvent()),
|
||||
child: const ProfileScreen(),
|
||||
),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/shop',
|
||||
builder: (_, __) => BlocProvider(
|
||||
create: (_) => ShopCubit(ShopRepository(api))..load(),
|
||||
create: (_) => locator<ShopBloc>()..add(LoadShopEvent()),
|
||||
child: const ShopScreen(),
|
||||
),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/vip',
|
||||
builder: (_, __) => BlocProvider(
|
||||
create: (_) => ShopCubit(ShopRepository(api))..load(),
|
||||
create: (_) => locator<ShopBloc>()..add(LoadShopEvent()),
|
||||
child: const VipScreen(),
|
||||
),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/private',
|
||||
builder: (_, __) => BlocProvider(
|
||||
create: (_) => locator<PrivateInfoBloc>(),
|
||||
child: const PrivateEntryScreen(),
|
||||
),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/private/room',
|
||||
builder: (_, st) {
|
||||
final create = st.uri.queryParameters['create'] == '1';
|
||||
final joinCode = st.uri.queryParameters['join'];
|
||||
final action = create
|
||||
? {'type': 'create_table'}
|
||||
: {'type': 'join_table', 'code': joinCode ?? ''};
|
||||
return BlocProvider(
|
||||
create: (_) =>
|
||||
locator<GameBloc>()..add(ConnectGameEvent(action)),
|
||||
child: const PrivateTableScreen(),
|
||||
);
|
||||
},
|
||||
),
|
||||
GoRoute(
|
||||
path: '/game/tiers',
|
||||
builder: (_, __) => TierListScreen(repo: GameRepository(api)),
|
||||
builder: (_, __) => BlocProvider(
|
||||
create: (_) => locator<TierBloc>()..add(LoadTiersEvent()),
|
||||
child: const TierListScreen(),
|
||||
),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/game/:tier',
|
||||
builder: (_, st) {
|
||||
final tier = st.pathParameters['tier']!;
|
||||
final prize = int.tryParse(st.uri.queryParameters['prize'] ?? '') ?? 0;
|
||||
return FutureBuilder<String?>(
|
||||
future: tokenStorage.read(),
|
||||
builder: (context, snap) {
|
||||
if (!snap.hasData) {
|
||||
return const Scaffold(
|
||||
body: Center(child: CircularProgressIndicator()));
|
||||
}
|
||||
return BlocProvider(
|
||||
create: (_) => GameCubit(WsClient(snap.data!), tier),
|
||||
child: GameScreen(prize: prize),
|
||||
);
|
||||
},
|
||||
final prize =
|
||||
int.tryParse(st.uri.queryParameters['prize'] ?? '') ?? 0;
|
||||
return BlocProvider(
|
||||
create: (_) => locator<GameBloc>()
|
||||
..add(ConnectGameEvent({'type': 'join_queue', 'tier': tier})),
|
||||
child: GameScreen(prize: prize),
|
||||
);
|
||||
},
|
||||
),
|
||||
@@ -118,15 +107,14 @@ class HakemApp extends StatelessWidget {
|
||||
|
||||
return MultiBlocProvider(
|
||||
providers: [
|
||||
BlocProvider(create: (_) => AuthCubit(authRepo)),
|
||||
BlocProvider(create: (_) => WalletCubit(api)),
|
||||
BlocProvider(create: (_) => locator<AuthBloc>()),
|
||||
BlocProvider(create: (_) => locator<WalletBloc>()),
|
||||
],
|
||||
child: MaterialApp.router(
|
||||
title: 'سلطان حکم',
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: AppTheme.build(),
|
||||
routerConfig: router,
|
||||
// اعمال راستبهچپ برای کل اپ.
|
||||
builder: (context, child) => Directionality(
|
||||
textDirection: TextDirection.rtl,
|
||||
child: child!,
|
||||
|
||||
Reference in New Issue
Block a user