PIbd-32_Shabunov_O.A._Mobil.../lib/main.dart

80 lines
2.6 KiB
Dart
Raw Normal View History

2024-12-12 13:54:24 +04:00
import 'dart:io';
2024-09-09 23:23:55 +04:00
import 'package:flutter/material.dart';
import 'package:flutter_android_app/presentation/favourites_bloc/favourites_bloc.dart';
2024-12-12 00:08:22 +04:00
import 'package:flutter_android_app/presentation/home_page/bloc/bloc.dart';
2024-10-03 00:24:49 +04:00
import 'package:flutter_android_app/presentation/home_page/home_page.dart';
2024-12-12 13:54:24 +04:00
import 'package:flutter_android_app/presentation/locale_bloc/locale_bloc.dart';
import 'package:flutter_android_app/presentation/locale_bloc/locale_state.dart';
import 'package:flutter_android_app/repositories/crypto_repository.dart';
2024-12-12 00:08:22 +04:00
import 'package:flutter_bloc/flutter_bloc.dart';
2024-09-09 23:23:55 +04:00
2024-12-12 13:54:24 +04:00
import 'components/locale/l10n/app_localizations.dart';
2024-09-09 23:23:55 +04:00
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
2024-09-09 23:23:55 +04:00
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
bool isDarkMode = false;
2024-09-09 23:23:55 +04:00
@override
Widget build(BuildContext context) {
return BlocProvider<FavouritesBloc>(
2024-12-12 13:54:24 +04:00
lazy: false,
create: (context) => FavouritesBloc(),
2024-12-12 13:54:24 +04:00
child: BlocProvider<LocaleBloc>(
lazy: false,
create: (context) => LocaleBloc(Locale(_getLangCode(Platform.localeName))),
2024-12-12 13:54:24 +04:00
child: BlocBuilder<LocaleBloc, LocaleState>(
builder: (context, state) => MaterialApp(
title: 'Cryptocurrency Exchange App',
2024-12-12 13:54:24 +04:00
locale: state.currentLocale,
localizationsDelegates: AppLocale.localizationsDelegates,
supportedLocales: AppLocale.supportedLocales,
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(
seedColor: Colors.indigoAccent,
brightness: isDarkMode ? Brightness.dark : Brightness.light,
),
2024-12-12 13:54:24 +04:00
useMaterial3: true,
brightness: isDarkMode ? Brightness.dark : Brightness.light,
2024-12-12 13:54:24 +04:00
),
debugShowCheckedModeBanner: false,
home: RepositoryProvider<CryptoRepository>(
2024-12-12 13:54:24 +04:00
lazy: true,
create: (_) => CryptoRepository(),
2024-12-12 13:54:24 +04:00
child: BlocProvider<HomeBloc>(
lazy: false,
create: (context) => HomeBloc(context.read<CryptoRepository>()),
child: MainScaffold(
toggleDarkMode: _toggleDarkMode,
isDarkModeSelected: isDarkMode,
),
2024-12-12 13:54:24 +04:00
),
),
),
2024-12-12 00:08:22 +04:00
),
),
2024-09-09 23:23:55 +04:00
);
}
void _toggleDarkMode() {
setState(() {
isDarkMode = !isDarkMode;
});
}
String _getLangCode(String fullLocaleName) {
int index = fullLocaleName.indexOf('_');
return index != -1 ? fullLocaleName.substring(0, index) : fullLocaleName;
}
2024-09-09 23:23:55 +04:00
}