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

60 lines
2.1 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 StatelessWidget {
const MyApp({super.key});
@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),
2024-12-12 13:54:24 +04:00
useMaterial3: true,
),
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: const MainScaffold(),
2024-12-12 13:54:24 +04:00
),
),
),
2024-12-12 00:08:22 +04:00
),
),
2024-09-09 23:23:55 +04:00
);
}
String _getLangCode(String fullLocaleName) {
int index = fullLocaleName.indexOf('_');
return index != -1 ? fullLocaleName.substring(0, index) : fullLocaleName;
}
2024-09-09 23:23:55 +04:00
}