1- import 'package:dynamic_color/dynamic_color.dart' ;
21import 'package:flutter/material.dart' ;
32import 'package:flutter_debug_overlay/flutter_debug_overlay.dart' ;
43import 'package:flutter_localizations/flutter_localizations.dart' ;
5- //import 'package:logger/logger.dart' hide LogEvent;
64import 'package:provider/provider.dart' ;
75
86import 'app_view_model.dart' ;
97import 'routing/router.dart' ;
8+ import 'theme/theme_wrapper.dart' ;
109
1110const double windowWidth = 360 ;
1211const double windowHeight = 640 ;
@@ -39,17 +38,16 @@ class App extends StatelessWidget {
3938 @override
4039 Widget build (BuildContext context) {
4140 final AppViewModel viewModel = context.read ();
42-
4341 return ListenableBuilder (
4442 listenable: viewModel,
4543 builder: (_, _) {
46- switch (viewModel.uiState) {
47- .loading () :
48- return const Text ( 'Loading...' ),
49- . success ( final shouldUseDynamicColor, final themeConfig) :
50- ThemeBuilder (
51- useDynamicColor : shouldUseDynamicColor ,
52- builder: (ThemeData theme, ThemeData darkTheme) {
44+ return switch (viewModel.uiState) {
45+ .loading () => const Text ( 'App loading...' ),
46+ . success ( final shouldUseDynamicColor, final themeConfig) =>
47+ ThemeWrapper (
48+ useDynamicColor : shouldUseDynamicColor
49+ themeConfig : themeConfig ,
50+ builder: (ThemeData theme, ThemeData darkTheme, ThemeMode themeMode ) {
5351 return MaterialApp .router (
5452 builder: (context, child) => DebugOverlay (
5553 logBucket: App .logBucket,
@@ -60,41 +58,15 @@ class App extends StatelessWidget {
6058 showPerformanceOverlay: false ,
6159 theme: theme,
6260 darkTheme: darkTheme,
63- themeMode: switch (viewModel.themeConfig) {
64- .followSystem => .system,
65- .light => .light,
66- .dark => .dark,
67- },
61+ themeMode: themeMode,
6862 routerConfig: router,
6963 localizationsDelegates: AppLocalizations .localizationsDelegates,
7064 supportedLocales: AppLocalizations .supportedLocales,
71- localeResolutionCallback: (locale, supportedLocales) {
72- return locale;
73- },
65+ localeResolutionCallback: (locale, _) => locale,
7466 );
7567 }
76- )
68+ ),
7769 }
78-
79- DynamicColorBuilder (
80- builder: (ColorScheme ? lightDynamic, ColorScheme ? darkDynamic) {
81- ThemeData theme = .light ();
82- ThemeData darkTheme = .dark ();
83- if (
84- viewModel.useDynamicColor &&
85- lightDynamic != null &&
86- darkDynamic != null
87- ) {
88- theme = theme.copyWith (colorScheme: lightDynamic);
89- darkTheme = theme.copyWith (colorScheme: darkDynamic);
90- }
91-
92- return ListenableBuilder (
93- listenable: viewModel.loadThemeConfig,
94- builder: (_, _) =>
95- );
96- },
97- ),
9870 );
9971 }
10072}
0 commit comments