|
| 1 | +import 'dart:async'; |
| 2 | + |
1 | 3 | import 'package:flutter/material.dart'; |
2 | 4 | import 'package:flutter/services.dart'; |
3 | 5 | import 'package:flutter_bloc/flutter_bloc.dart'; |
@@ -42,19 +44,13 @@ void main() async { |
42 | 44 | MultiBlocProvider( |
43 | 45 | providers: [ |
44 | 46 | BlocProvider<AuthenticationBloc>( |
45 | | - create: (context) { |
46 | | - return AuthenticationBloc()..add(const AppStarted()); |
47 | | - }, |
| 47 | + create: (context) => AuthenticationBloc()..add(const AppStarted()), |
48 | 48 | ), |
49 | 49 | BlocProvider<RecipesShortBloc>( |
50 | | - create: (context) { |
51 | | - return RecipesShortBloc(); |
52 | | - }, |
| 50 | + create: (context) => RecipesShortBloc(), |
53 | 51 | ), |
54 | 52 | BlocProvider<CategoriesBloc>( |
55 | | - create: (context) { |
56 | | - return CategoriesBloc(); |
57 | | - }, |
| 53 | + create: (context) => CategoriesBloc(), |
58 | 54 | ) |
59 | 55 | ], |
60 | 56 | child: const App(), |
@@ -87,51 +83,49 @@ class _AppState extends State<App> { |
87 | 83 | final savedLocalization = Settings.getValue<String>( |
88 | 84 | SettingKeys.language.name, |
89 | 85 | ); |
90 | | - changeLocale(context, savedLocalization); |
| 86 | + unawaited(changeLocale(context, savedLocalization)); |
91 | 87 | } |
92 | 88 |
|
93 | 89 | @override |
94 | | - Widget build(BuildContext context) { |
95 | | - return ThemeModeHandler( |
96 | | - manager: ThemeModeManager(), |
97 | | - builder: (ThemeMode themeMode) => MaterialApp( |
98 | | - navigatorKey: IntentRepository().getNavigationKey(), |
99 | | - themeMode: themeMode, |
100 | | - theme: AppTheme.lightThemeData, |
101 | | - darkTheme: AppTheme.darkThemeData, |
102 | | - home: BlocConsumer<AuthenticationBloc, AuthenticationState>( |
103 | | - builder: (context, state) { |
104 | | - SystemChrome.setSystemUIOverlayStyle( |
105 | | - SystemUiOverlayStyle( |
106 | | - systemNavigationBarColor: |
107 | | - Theme.of(context).scaffoldBackgroundColor, |
108 | | - ), |
109 | | - ); |
| 90 | + Widget build(BuildContext context) => ThemeModeHandler( |
| 91 | + manager: ThemeModeManager(), |
| 92 | + builder: (themeMode) => MaterialApp( |
| 93 | + navigatorKey: IntentRepository().getNavigationKey(), |
| 94 | + themeMode: themeMode, |
| 95 | + theme: AppTheme.lightThemeData, |
| 96 | + darkTheme: AppTheme.darkThemeData, |
| 97 | + home: BlocConsumer<AuthenticationBloc, AuthenticationState>( |
| 98 | + builder: (context, state) { |
| 99 | + SystemChrome.setSystemUIOverlayStyle( |
| 100 | + SystemUiOverlayStyle( |
| 101 | + systemNavigationBarColor: |
| 102 | + Theme.of(context).scaffoldBackgroundColor, |
| 103 | + ), |
| 104 | + ); |
110 | 105 |
|
111 | | - switch (state.status) { |
112 | | - case AuthenticationStatus.loading: |
113 | | - return const SplashPage(); |
114 | | - case AuthenticationStatus.authenticated: |
115 | | - return const CategoryScreen(); |
116 | | - case AuthenticationStatus.unauthenticated: |
117 | | - return const LoginScreen(); |
118 | | - case AuthenticationStatus.invalid: |
119 | | - return const LoginScreen( |
120 | | - invalidCredentials: true, |
121 | | - ); |
122 | | - case AuthenticationStatus.error: |
123 | | - return LoadingErrorScreen(message: state.error!); |
124 | | - } |
125 | | - }, |
126 | | - listener: (context, state) async { |
127 | | - if (state.status != AuthenticationStatus.loading) { |
128 | | - FlutterNativeSplash.remove(); |
129 | | - } else if (state.status == AuthenticationStatus.authenticated) { |
130 | | - await IntentRepository().handleIntent(); |
131 | | - } |
132 | | - }, |
| 106 | + switch (state.status) { |
| 107 | + case AuthenticationStatus.loading: |
| 108 | + return const SplashPage(); |
| 109 | + case AuthenticationStatus.authenticated: |
| 110 | + return const CategoryScreen(); |
| 111 | + case AuthenticationStatus.unauthenticated: |
| 112 | + return const LoginScreen(); |
| 113 | + case AuthenticationStatus.invalid: |
| 114 | + return const LoginScreen( |
| 115 | + invalidCredentials: true, |
| 116 | + ); |
| 117 | + case AuthenticationStatus.error: |
| 118 | + return LoadingErrorScreen(message: state.error!); |
| 119 | + } |
| 120 | + }, |
| 121 | + listener: (context, state) async { |
| 122 | + if (state.status != AuthenticationStatus.loading) { |
| 123 | + FlutterNativeSplash.remove(); |
| 124 | + } else if (state.status == AuthenticationStatus.authenticated) { |
| 125 | + await IntentRepository().handleIntent(); |
| 126 | + } |
| 127 | + }, |
| 128 | + ), |
133 | 129 | ), |
134 | | - ), |
135 | | - ); |
136 | | - } |
| 130 | + ); |
137 | 131 | } |
0 commit comments