Initializes internationalization (i18n) for the application. Introduces `AppLocalizations` to manage localized strings, along with English and Russian translations. Configures Flutter to use the localization delegates and supported locales. This allows the app to display text in the user's preferred language.
67 lines
2.5 KiB
Dart
67 lines
2.5 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/home_page.dart';
|
|
import 'theme/app_theme.dart';
|
|
import 'injection_container.dart' as di;
|
|
import 'logic/settings/settings_cubit.dart'; // Импортируем SettingsCubit
|
|
import 'logic/transaction/transaction_bloc.dart';
|
|
|
|
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>()),
|
|
BlocProvider(create: (context) => GetIt.instance<TransactionBloc>()),
|
|
],
|
|
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();
|
|
}
|
|
},
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|