103 lines
3.7 KiB
Dart
103 lines
3.7 KiB
Dart
import 'package:budget_app/pages/home/home_page.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:flutter_localizations/flutter_localizations.dart'; // Добавляем импорт
|
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
|
import 'package:get_it/get_it.dart';
|
|
|
|
import '/l10n/app_localizations.dart';
|
|
import '/pages/splash/splash_screen.dart';
|
|
import 'injection_container.dart' as di;
|
|
import 'logic/auth/auth_bloc.dart';
|
|
import 'logic/settings/settings_cubit.dart'; // Импортируем SettingsCubit
|
|
import 'logic/transaction/transaction_bloc.dart';
|
|
import 'logic/user/user_cubit.dart'; // Импортируем UserCubit
|
|
import 'pages/login/login_page.dart';
|
|
import 'theme/app_theme.dart';
|
|
|
|
void main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
await dotenv.load(fileName: ".env");
|
|
await di.initGlobalDependencies();
|
|
runApp(const MyApp());
|
|
}
|
|
|
|
class MyApp extends StatelessWidget {
|
|
const MyApp({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MultiBlocProvider(
|
|
providers: [
|
|
BlocProvider(
|
|
create: (context) => GetIt.instance<UserCubit>(),
|
|
),
|
|
BlocProvider(
|
|
create: (context) => GetIt.instance<AuthBloc>()..add(AuthStarted()),
|
|
),
|
|
],
|
|
child: BlocBuilder<AuthBloc, AuthState>(
|
|
builder: (context, authState) {
|
|
if (authState is AuthAuthenticated) {
|
|
return MultiBlocProvider(
|
|
providers: [
|
|
BlocProvider(create: (context) => GetIt.instance<SettingsCubit>()),
|
|
BlocProvider(create: (context) => GetIt.instance<TransactionBloc>()),
|
|
],
|
|
child: BlocBuilder<SettingsCubit, SettingsState>(
|
|
builder: (context, settingsState) {
|
|
final isDarkMode = settingsState is SettingsLoaded
|
|
? settingsState.isDarkMode
|
|
: false;
|
|
final languageCode = settingsState is SettingsLoaded
|
|
? settingsState.languageCode
|
|
: 'ru';
|
|
|
|
return MaterialApp(
|
|
title: 'Budget App',
|
|
theme: AppTheme.lightTheme(),
|
|
darkTheme: AppTheme.darkTheme(),
|
|
themeMode: isDarkMode ? ThemeMode.dark : ThemeMode.light,
|
|
localizationsDelegates: const [
|
|
AppLocalizations.delegate,
|
|
GlobalMaterialLocalizations.delegate,
|
|
GlobalWidgetsLocalizations.delegate,
|
|
GlobalCupertinoLocalizations.delegate,
|
|
],
|
|
supportedLocales: AppLocalizations.supportedLocales,
|
|
locale: Locale(languageCode),
|
|
home: const HomePage(),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget homeWidget;
|
|
if (authState is AuthInitial) {
|
|
homeWidget = const SplashScreen();
|
|
} else {
|
|
homeWidget = const LoginPage();
|
|
}
|
|
|
|
return MaterialApp(
|
|
title: 'Budget App',
|
|
theme: AppTheme.lightTheme(),
|
|
darkTheme: AppTheme.darkTheme(),
|
|
themeMode: ThemeMode.light, // Тема по умолчанию
|
|
localizationsDelegates: const [
|
|
AppLocalizations.delegate,
|
|
GlobalMaterialLocalizations.delegate,
|
|
GlobalWidgetsLocalizations.delegate,
|
|
GlobalCupertinoLocalizations.delegate,
|
|
],
|
|
supportedLocales: AppLocalizations.supportedLocales,
|
|
locale: const Locale('ru'), // Язык по умолчанию
|
|
home: homeWidget,
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|