80 lines
2.5 KiB
Dart
80 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_page.dart';
|
|
import 'theme/app_theme.dart';
|
|
import 'package:hive_ce_flutter/hive_flutter.dart';
|
|
import 'injection_container.dart' as di;
|
|
import 'services/settings_service.dart';
|
|
import 'package:get_it/get_it.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> {
|
|
late final SettingsService _settingsService;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_settingsService = GetIt.instance<SettingsService>();
|
|
_settingsService.addListener(_onSettingsChanged);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_settingsService.removeListener(_onSettingsChanged);
|
|
super.dispose();
|
|
}
|
|
|
|
void _onSettingsChanged() {
|
|
setState(() {});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return BlocProvider(
|
|
create: (context) => GetIt.instance<AuthBloc>()..add(AuthStarted()),
|
|
child: MaterialApp(
|
|
title: AppLocalizations.of(context)?.appTitle ?? 'Budget App', // Используем локализованный заголовок
|
|
theme: AppTheme.lightTheme(),
|
|
darkTheme: AppTheme.darkTheme(),
|
|
themeMode: _settingsService.isDarkMode ? ThemeMode.dark : ThemeMode.light,
|
|
// Добавляем локализацию
|
|
localizationsDelegates: const [
|
|
AppLocalizations.delegate,
|
|
GlobalMaterialLocalizations.delegate,
|
|
GlobalWidgetsLocalizations.delegate,
|
|
GlobalCupertinoLocalizations.delegate,
|
|
],
|
|
supportedLocales: AppLocalizations.supportedLocales,
|
|
locale: Locale(_settingsService.languageCode), // Устанавливаем текущий язык из настроек
|
|
home: BlocBuilder<AuthBloc, AuthState>(
|
|
builder: (context, state) {
|
|
if (state is AuthAuthenticated) {
|
|
return const HomePage();
|
|
} else {
|
|
return const LoginPage();
|
|
}
|
|
},
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|