1
1
//
2
2
// ignore_for_file: deprecated_member_use
3
3
4
+ import 'package:flex_color_scheme/flex_color_scheme.dart' ;
4
5
import 'package:flutter/material.dart' ;
5
6
import 'package:flutter_bloc/flutter_bloc.dart' ;
6
7
import 'package:go_router/go_router.dart' ;
@@ -11,6 +12,9 @@ import 'package:ht_dashboard/app_configuration/bloc/app_configuration_bloc.dart'
11
12
import 'package:ht_dashboard/authentication/bloc/authentication_bloc.dart' ;
12
13
import 'package:ht_dashboard/l10n/app_localizations.dart' ;
13
14
import 'package:ht_dashboard/router/router.dart' ;
15
+ import 'package:ht_dashboard/shared/theme/app_theme.dart'
16
+ as app_theme_extension; // Import for app_theme.dart
17
+ import 'package:ht_dashboard/shared/theme/app_theme.dart' ;
14
18
import 'package:ht_data_repository/ht_data_repository.dart' ;
15
19
import 'package:ht_kv_storage_service/ht_kv_storage_service.dart' ;
16
20
import 'package:ht_shared/ht_shared.dart' ;
@@ -135,12 +139,37 @@ class _AppViewState extends State<_AppView> {
135
139
@override
136
140
Widget build (BuildContext context) {
137
141
return BlocListener <AppBloc , AppState >(
138
- listenWhen: (previous, current) => previous.status != current.status,
142
+ listenWhen: (previous, current) =>
143
+ previous.status != current.status ||
144
+ previous.userAppSettings != current.userAppSettings,
139
145
listener: (context, state) {
140
146
_statusNotifier.value = state.status;
141
147
},
142
148
child: BlocBuilder <AppBloc , AppState >(
143
149
builder: (context, state) {
150
+ final userAppSettings = state.userAppSettings;
151
+ final baseTheme = userAppSettings? .displaySettings.baseTheme;
152
+ final accentTheme = userAppSettings? .displaySettings.accentTheme;
153
+ final fontFamily = userAppSettings? .displaySettings.fontFamily;
154
+ final textScaleFactor =
155
+ userAppSettings? .displaySettings.textScaleFactor;
156
+ final fontWeight = userAppSettings? .displaySettings.fontWeight;
157
+ final language = userAppSettings? .language;
158
+
159
+ final lightThemeData = lightTheme (
160
+ scheme: accentTheme? .toFlexScheme ?? FlexScheme .materialHc,
161
+ appTextScaleFactor: textScaleFactor ?? AppTextScaleFactor .medium,
162
+ appFontWeight: fontWeight ?? AppFontWeight .regular,
163
+ fontFamily: fontFamily,
164
+ );
165
+
166
+ final darkThemeData = darkTheme (
167
+ scheme: accentTheme? .toFlexScheme ?? FlexScheme .materialHc,
168
+ appTextScaleFactor: textScaleFactor ?? AppTextScaleFactor .medium,
169
+ appFontWeight: fontWeight ?? AppFontWeight .regular,
170
+ fontFamily: fontFamily,
171
+ );
172
+
144
173
const double kMaxAppWidth = 1000 ; // Local constant for max width
145
174
return Center (
146
175
child: Card (
@@ -159,6 +188,16 @@ class _AppViewState extends State<_AppView> {
159
188
localizationsDelegates:
160
189
AppLocalizations .localizationsDelegates,
161
190
supportedLocales: AppLocalizations .supportedLocales,
191
+ theme: baseTheme == AppBaseTheme .dark
192
+ ? darkThemeData
193
+ : lightThemeData,
194
+ darkTheme: darkThemeData,
195
+ themeMode: switch (baseTheme) {
196
+ AppBaseTheme .light => ThemeMode .light,
197
+ AppBaseTheme .dark => ThemeMode .dark,
198
+ AppBaseTheme .system || null => ThemeMode .system,
199
+ },
200
+ locale: language != null ? Locale (language) : null ,
162
201
),
163
202
),
164
203
),
@@ -168,3 +207,16 @@ class _AppViewState extends State<_AppView> {
168
207
);
169
208
}
170
209
}
210
+
211
+ extension AppAccentThemeExtension on AppAccentTheme {
212
+ FlexScheme get toFlexScheme {
213
+ switch (this ) {
214
+ case AppAccentTheme .defaultBlue:
215
+ return FlexScheme .materialHc;
216
+ case AppAccentTheme .newsRed:
217
+ return FlexScheme .redWine;
218
+ case AppAccentTheme .graphiteGray:
219
+ return FlexScheme .outerSpace;
220
+ }
221
+ }
222
+ }
0 commit comments