Skip to content

Commit d794adf

Browse files
committed
feat: implement dynamic theme settings
- Added theme customization options - Integrated FlexColorScheme - Added theme extensions
1 parent 897da64 commit d794adf

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

lib/app/view/app.dart

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//
22
// ignore_for_file: deprecated_member_use
33

4+
import 'package:flex_color_scheme/flex_color_scheme.dart';
45
import 'package:flutter/material.dart';
56
import 'package:flutter_bloc/flutter_bloc.dart';
67
import 'package:go_router/go_router.dart';
@@ -11,6 +12,9 @@ import 'package:ht_dashboard/app_configuration/bloc/app_configuration_bloc.dart'
1112
import 'package:ht_dashboard/authentication/bloc/authentication_bloc.dart';
1213
import 'package:ht_dashboard/l10n/app_localizations.dart';
1314
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';
1418
import 'package:ht_data_repository/ht_data_repository.dart';
1519
import 'package:ht_kv_storage_service/ht_kv_storage_service.dart';
1620
import 'package:ht_shared/ht_shared.dart';
@@ -135,12 +139,37 @@ class _AppViewState extends State<_AppView> {
135139
@override
136140
Widget build(BuildContext context) {
137141
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,
139145
listener: (context, state) {
140146
_statusNotifier.value = state.status;
141147
},
142148
child: BlocBuilder<AppBloc, AppState>(
143149
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+
144173
const double kMaxAppWidth = 1000; // Local constant for max width
145174
return Center(
146175
child: Card(
@@ -159,6 +188,16 @@ class _AppViewState extends State<_AppView> {
159188
localizationsDelegates:
160189
AppLocalizations.localizationsDelegates,
161190
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,
162201
),
163202
),
164203
),
@@ -168,3 +207,16 @@ class _AppViewState extends State<_AppView> {
168207
);
169208
}
170209
}
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

Comments
 (0)