67 lines
2.4 KiB
Dart
67 lines
2.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:get_it/get_it.dart';
|
|
import 'package:flutter_localizations/flutter_localizations.dart'; // Добавляем импорт
|
|
import '/l10n/app_localizations.dart';
|
|
import 'logic/auth/auth_bloc.dart';
|
|
import 'pages/login/login_page.dart';
|
|
import 'package:budget_app/pages/home_page.dart';
|
|
import 'theme/app_theme.dart';
|
|
import 'injection_container.dart' as di;
|
|
import 'logic/settings/settings_cubit.dart'; // Импортируем SettingsCubit
|
|
|
|
void main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
await di.initDependencies();
|
|
runApp(const MyApp());
|
|
}
|
|
|
|
class MyApp extends StatefulWidget {
|
|
const MyApp({super.key});
|
|
|
|
@override
|
|
State<MyApp> createState() => _MyAppState();
|
|
}
|
|
|
|
class _MyAppState extends State<MyApp> {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MultiBlocProvider(
|
|
providers: [
|
|
BlocProvider(create: (context) => GetIt.instance<AuthBloc>()..add(AuthStarted())),
|
|
BlocProvider(create: (context) => GetIt.instance<SettingsCubit>()),
|
|
],
|
|
child: BlocBuilder<SettingsCubit, SettingsState>(
|
|
builder: (context, settingsState) {
|
|
return MaterialApp(
|
|
title: AppLocalizations.of(context)?.appTitle ?? 'Budget App', // Используем локализованный заголовок
|
|
theme: AppTheme.lightTheme(),
|
|
darkTheme: AppTheme.darkTheme(),
|
|
themeMode: settingsState.isDarkMode ? ThemeMode.dark : ThemeMode.light,
|
|
// Добавляем локализацию
|
|
localizationsDelegates: const [
|
|
AppLocalizations.delegate,
|
|
GlobalMaterialLocalizations.delegate,
|
|
GlobalWidgetsLocalizations.delegate,
|
|
GlobalCupertinoLocalizations.delegate,
|
|
],
|
|
supportedLocales: AppLocalizations.supportedLocales,
|
|
locale: Locale(settingsState.languageCode), // Устанавливаем текущий язык из настроек
|
|
home: BlocBuilder<AuthBloc, AuthState>(
|
|
builder: (context, authState) {
|
|
if (authState is AuthAuthenticated) {
|
|
return const HomePage();
|
|
} else {
|
|
return const LoginPage();
|
|
}
|
|
},
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
|