91 lines
2.9 KiB
Dart
91 lines
2.9 KiB
Dart
/// Application entry point and root widget composition.
|
|
///
|
|
/// Wires core services, repositories, BLoCs, and routing for the Prediqo mobile app.
|
|
library;
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'app_router.dart';
|
|
import 'core/api/api_client.dart';
|
|
import 'core/services/exchange_rate_service.dart';
|
|
import 'core/theme/app_theme.dart';
|
|
import 'data/repositories/admin_repository_impl.dart';
|
|
import 'data/repositories/auth_repository_impl.dart';
|
|
import 'data/repositories/wallet_repository_impl.dart';
|
|
import 'features/auth/bloc/auth_bloc.dart';
|
|
import 'features/wallet/bloc/wallet_bloc.dart';
|
|
|
|
/// Initializes bindings, constructs dependencies, and runs the app.
|
|
void main() {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
const baseUrl = String.fromEnvironment(
|
|
'API_BASE_URL',
|
|
defaultValue: 'http://172.31.9.51:4000', // Android emulator localhost
|
|
);
|
|
final apiClient = ApiClient(baseUrl: baseUrl);
|
|
final authRepo = AuthRepositoryImpl(apiClient);
|
|
final walletRepo = WalletRepositoryImpl(apiClient);
|
|
final adminRepo = AdminRepositoryImpl(apiClient);
|
|
final exchangeRateService = ExchangeRateService();
|
|
|
|
runApp(
|
|
MyApp(
|
|
apiClient: apiClient,
|
|
authRepo: authRepo,
|
|
walletRepo: walletRepo,
|
|
adminRepo: adminRepo,
|
|
exchangeRateService: exchangeRateService,
|
|
),
|
|
);
|
|
}
|
|
|
|
/// Root widget that provides repositories, BLoCs, and themed routing.
|
|
class MyApp extends StatelessWidget {
|
|
/// Creates the app with pre-built core dependencies from [main].
|
|
const MyApp({
|
|
super.key,
|
|
required this.apiClient,
|
|
required this.authRepo,
|
|
required this.walletRepo,
|
|
required this.adminRepo,
|
|
required this.exchangeRateService,
|
|
});
|
|
|
|
final ApiClient apiClient;
|
|
final AuthRepositoryImpl authRepo;
|
|
final WalletRepositoryImpl walletRepo;
|
|
final AdminRepositoryImpl adminRepo;
|
|
final ExchangeRateService exchangeRateService;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MultiRepositoryProvider(
|
|
providers: [
|
|
RepositoryProvider<ApiClient>.value(value: apiClient),
|
|
RepositoryProvider<AuthRepositoryImpl>.value(value: authRepo),
|
|
RepositoryProvider<WalletRepositoryImpl>.value(value: walletRepo),
|
|
RepositoryProvider<AdminRepositoryImpl>.value(value: adminRepo),
|
|
RepositoryProvider<ExchangeRateService>.value(
|
|
value: exchangeRateService,
|
|
),
|
|
],
|
|
child: MultiBlocProvider(
|
|
providers: [
|
|
BlocProvider(
|
|
create: (_) => AuthBloc(authRepo)..add(const AuthCheckRequested()),
|
|
),
|
|
BlocProvider(create: (_) => WalletBloc(walletRepo)),
|
|
],
|
|
child: MaterialApp.router(
|
|
title: 'Prediqo',
|
|
debugShowCheckedModeBanner: false,
|
|
theme: AppTheme.light,
|
|
darkTheme: AppTheme.dark,
|
|
themeMode: ThemeMode.system,
|
|
routerConfig: createAppRouter(),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|