feat:theme changing done
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import 'package:food_delivery_client/feature/common/presentation/blocs/theme_bloc/theme_bloc.dart';
|
||||
import 'package:toastification/toastification.dart';
|
||||
|
||||
import 'food_delivery_client.dart';
|
||||
|
||||
void main() {
|
||||
@@ -13,7 +13,13 @@ void main() {
|
||||
Bloc.observer = AppBlocObserver();
|
||||
await configureDependencies();
|
||||
runApp(
|
||||
BlocProvider(create: (context) => sl<LanguageBloc>(), child: MyApp()),
|
||||
MultiBlocProvider(
|
||||
providers: [
|
||||
BlocProvider(create: (context) => sl<LanguageBloc>()),
|
||||
BlocProvider(create: (context) => sl<ThemeBloc>()),
|
||||
],
|
||||
child: MyApp(),
|
||||
),
|
||||
);
|
||||
},
|
||||
(error, stack) {
|
||||
@@ -32,46 +38,54 @@ class MyApp extends StatefulWidget {
|
||||
class _MyAppState extends State<MyApp> {
|
||||
@override
|
||||
void initState() {
|
||||
SystemChrome.setPreferredOrientations([
|
||||
DeviceOrientation.portraitUp,
|
||||
DeviceOrientation.portraitDown,
|
||||
]);
|
||||
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
||||
SystemChrome.setPreferredOrientations([
|
||||
DeviceOrientation.portraitUp,
|
||||
DeviceOrientation.portraitDown,
|
||||
]);
|
||||
context.read<LanguageBloc>().add(LanguageEvent.started());
|
||||
context.read<ThemeBloc>().add(ThemeEvent.started());
|
||||
});
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<LanguageBloc, LanguageState>(
|
||||
bloc: context.read<LanguageBloc>()..add(LanguageEvent.started()),
|
||||
builder: (context, state) {
|
||||
return ToastificationWrapper(
|
||||
child: MaterialApp.router(
|
||||
title: AppLocaleKeys.appName,
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: AppTheme.lightTheme,
|
||||
darkTheme: AppTheme.darkTheme,
|
||||
themeMode: ThemeMode.light,
|
||||
routerConfig: sl<AppRoutes>().router,
|
||||
locale: state.currentLocale,
|
||||
supportedLocales: L10n.locales,
|
||||
localizationsDelegates: [
|
||||
AppLocalizations.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
builder: (context, child) => GestureDetector(
|
||||
onTap: () {
|
||||
FocusManager.instance.primaryFocus?.unfocus();
|
||||
},
|
||||
child: MediaQuery(
|
||||
data: MediaQuery.of(
|
||||
context,
|
||||
).copyWith(textScaler: const TextScaler.linear(1)),
|
||||
child: child!,
|
||||
return BlocBuilder<ThemeBloc, ThemeState>(
|
||||
builder: (context, themeState) {
|
||||
return ToastificationWrapper(
|
||||
child: MaterialApp.router(
|
||||
title: AppLocaleKeys.appName,
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: AppTheme.lightTheme,
|
||||
darkTheme: AppTheme.darkTheme,
|
||||
themeMode: themeState.themeMode,
|
||||
routerConfig: sl<AppRoutes>().router,
|
||||
locale: state.currentLocale,
|
||||
supportedLocales: L10n.locales,
|
||||
localizationsDelegates: [
|
||||
AppLocalizations.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
builder: (context, child) => GestureDetector(
|
||||
onTap: () {
|
||||
FocusManager.instance.primaryFocus?.unfocus();
|
||||
},
|
||||
child: MediaQuery(
|
||||
data: MediaQuery.of(
|
||||
context,
|
||||
).copyWith(textScaler: const TextScaler.linear(1)),
|
||||
child: child!,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user