|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:flutter_bloc/flutter_bloc.dart'; |
| 3 | +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; |
| 4 | +import 'package:flutter_localizations/flutter_localizations.dart'; |
| 5 | + |
| 6 | +import 'bloc/language/language_cubit.dart'; |
| 7 | +import 'bloc/post/post_cubit.dart'; |
| 8 | +import 'bloc/theme/theme_cubit.dart'; |
| 9 | +import 'constants/app_themes.dart'; |
| 10 | +import 'constants/supported_locales.dart'; |
| 11 | +import 'data/repositories/post_repository.dart'; |
| 12 | +import 'presentation/pages/posts/posts_page.dart'; |
| 13 | + |
| 14 | +class App extends StatelessWidget { |
| 15 | + @override |
| 16 | + Widget build(BuildContext context) { |
| 17 | + final themeMode = context.watch<ThemeCubit>().state; |
| 18 | + final locale = context.watch<LanguageCubit>().state; |
| 19 | + |
| 20 | + return MaterialApp( |
| 21 | + title: 'Placeholder Title', |
| 22 | + debugShowCheckedModeBanner: false, |
| 23 | + themeMode: themeMode, |
| 24 | + theme: AppThemes.lightTheme, |
| 25 | + darkTheme: AppThemes.darkTheme, |
| 26 | + locale: locale, |
| 27 | + supportedLocales: supportedLocales, |
| 28 | + localizationsDelegates: [ |
| 29 | + GlobalMaterialLocalizations.delegate, |
| 30 | + GlobalWidgetsLocalizations.delegate, |
| 31 | + GlobalCupertinoLocalizations.delegate, |
| 32 | + AppLocalizations.delegate, |
| 33 | + ], |
| 34 | + home: Navigator( |
| 35 | + pages: [ |
| 36 | + MaterialPage( |
| 37 | + child: RepositoryProvider( |
| 38 | + create: (_) => PostRepository(), |
| 39 | + child: BlocProvider( |
| 40 | + create: (ctx) => PostCubit( |
| 41 | + ctx.read<PostRepository>(), |
| 42 | + )..fetch(), |
| 43 | + child: PostsPage(), |
| 44 | + ), |
| 45 | + ), |
| 46 | + ), |
| 47 | + ], |
| 48 | + onPopPage: (route, result) { |
| 49 | + if (route.didPop(result)) { |
| 50 | + return true; |
| 51 | + } |
| 52 | + |
| 53 | + return false; |
| 54 | + }, |
| 55 | + ), |
| 56 | + ); |
| 57 | + } |
| 58 | +} |
0 commit comments