Skip to content

Commit 9cb6198

Browse files
authored
Merge pull request #8 from headlines-toolkit/fix_settings_feature
Fix settings feature
2 parents 2e475a5 + ad5a013 commit 9cb6198

File tree

9 files changed

+424
-290
lines changed

9 files changed

+424
-290
lines changed

lib/l10n/app_localizations.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,30 @@ abstract class AppLocalizations {
931931
/// In en, this message translates to:
932932
/// **'Arabic'**
933933
String get arabicLanguage;
934+
935+
/// Label for the Appearance settings tab
936+
///
937+
/// In en, this message translates to:
938+
/// **'Appearance'**
939+
String get appearanceSettingsLabel;
940+
941+
/// Label for the Language settings tab
942+
///
943+
/// In en, this message translates to:
944+
/// **'Language'**
945+
String get languageSettingsLabel;
946+
947+
/// Label for the Theme Settings sub-tab
948+
///
949+
/// In en, this message translates to:
950+
/// **'Theme Settings'**
951+
String get themeSettingsLabel;
952+
953+
/// Label for the Font Settings sub-tab
954+
///
955+
/// In en, this message translates to:
956+
/// **'Font Settings'**
957+
String get fontSettingsLabel;
934958
}
935959

936960
class _AppLocalizationsDelegate

lib/l10n/app_localizations_ar.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,4 +487,16 @@ class AppLocalizationsAr extends AppLocalizations {
487487

488488
@override
489489
String get arabicLanguage => 'العربية';
490+
491+
@override
492+
String get appearanceSettingsLabel => 'المظهر';
493+
494+
@override
495+
String get languageSettingsLabel => 'اللغة';
496+
497+
@override
498+
String get themeSettingsLabel => 'إعدادات السمة';
499+
500+
@override
501+
String get fontSettingsLabel => 'إعدادات الخط';
490502
}

lib/l10n/app_localizations_en.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,4 +485,16 @@ class AppLocalizationsEn extends AppLocalizations {
485485

486486
@override
487487
String get arabicLanguage => 'Arabic';
488+
489+
@override
490+
String get appearanceSettingsLabel => 'Appearance';
491+
492+
@override
493+
String get languageSettingsLabel => 'Language';
494+
495+
@override
496+
String get themeSettingsLabel => 'Theme Settings';
497+
498+
@override
499+
String get fontSettingsLabel => 'Font Settings';
488500
}

lib/l10n/arb/app_ar.arb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,5 +579,21 @@
579579
"arabicLanguage": "العربية",
580580
"@arabicLanguage": {
581581
"description": "خيار اللغة العربية"
582+
},
583+
"appearanceSettingsLabel": "المظهر",
584+
"@appearanceSettingsLabel": {
585+
"description": "تسمية تبويب إعدادات المظهر"
586+
},
587+
"languageSettingsLabel": "اللغة",
588+
"@languageSettingsLabel": {
589+
"description": "تسمية تبويب إعدادات اللغة"
590+
},
591+
"themeSettingsLabel": "إعدادات السمة",
592+
"@themeSettingsLabel": {
593+
"description": "تسمية تبويب إعدادات السمة الفرعي"
594+
},
595+
"fontSettingsLabel": "إعدادات الخط",
596+
"@fontSettingsLabel": {
597+
"description": "تسمية تبويب إعدادات الخط الفرعي"
582598
}
583599
}

lib/l10n/arb/app_en.arb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,5 +579,21 @@
579579
"arabicLanguage": "Arabic",
580580
"@arabicLanguage": {
581581
"description": "Option for Arabic language"
582+
},
583+
"appearanceSettingsLabel": "Appearance",
584+
"@appearanceSettingsLabel": {
585+
"description": "Label for the Appearance settings tab"
586+
},
587+
"languageSettingsLabel": "Language",
588+
"@languageSettingsLabel": {
589+
"description": "Label for the Language settings tab"
590+
},
591+
"themeSettingsLabel": "Theme Settings",
592+
"@themeSettingsLabel": {
593+
"description": "Label for the Theme Settings sub-tab"
594+
},
595+
"fontSettingsLabel": "Font Settings",
596+
"@fontSettingsLabel": {
597+
"description": "Label for the Font Settings sub-tab"
582598
}
583599
}

lib/router/router.dart

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,17 @@ GoRouter createRouter({
140140
path: Routes.dashboard,
141141
name: Routes.dashboardName,
142142
builder: (context, state) => const DashboardPage(),
143+
routes: [
144+
// The settings page is a sub-route of the dashboard.
145+
// This allows it to be displayed within the AppShell
146+
// (with sidebar and top bar visible) without adding
147+
// a new item to the main navigation sidebar.
148+
GoRoute(
149+
path: Routes.settings,
150+
name: Routes.settingsName,
151+
builder: (context, state) => const SettingsPage(),
152+
),
153+
],
143154
),
144155
],
145156
),
@@ -180,11 +191,6 @@ GoRouter createRouter({
180191
),
181192
],
182193
),
183-
GoRoute(
184-
path: Routes.settings,
185-
name: Routes.settingsName,
186-
builder: (context, state) => const SettingsPage(),
187-
),
188194
],
189195
);
190196
}

lib/settings/bloc/settings_bloc.dart

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class SettingsBloc extends Bloc<SettingsEvent, SettingsState> {
1212
SettingsBloc({
1313
required HtDataRepository<UserAppSettings> userAppSettingsRepository,
1414
}) : _userAppSettingsRepository = userAppSettingsRepository,
15-
super(SettingsInitial()) {
15+
super(const SettingsInitial()) {
1616
on<SettingsLoaded>(_onSettingsLoaded);
1717
on<SettingsBaseThemeChanged>(_onSettingsBaseThemeChanged);
1818
on<SettingsAccentThemeChanged>(_onSettingsAccentThemeChanged);
@@ -28,9 +28,8 @@ class SettingsBloc extends Bloc<SettingsEvent, SettingsState> {
2828
SettingsLoaded event,
2929
Emitter<SettingsState> emit,
3030
) async {
31-
emit(SettingsLoadInProgress());
31+
emit(SettingsLoadInProgress(userAppSettings: state.userAppSettings));
3232
try {
33-
// Assuming a fixed ID for user settings, or fetching based on current user
3433
final userAppSettings = await _userAppSettingsRepository.read(
3534
id: event.userId!,
3635
);
@@ -40,9 +39,9 @@ class SettingsBloc extends Bloc<SettingsEvent, SettingsState> {
4039
await _userAppSettingsRepository.create(item: defaultSettings);
4140
emit(SettingsLoadSuccess(userAppSettings: defaultSettings));
4241
} on HtHttpException catch (e) {
43-
emit(SettingsLoadFailure(e.message));
42+
emit(SettingsLoadFailure(e.message, userAppSettings: state.userAppSettings));
4443
} catch (e) {
45-
emit(SettingsLoadFailure('An unexpected error occurred: $e'));
44+
emit(SettingsLoadFailure('An unexpected error occurred: $e', userAppSettings: state.userAppSettings));
4645
}
4746
}
4847

@@ -58,18 +57,18 @@ class SettingsBloc extends Bloc<SettingsEvent, SettingsState> {
5857
);
5958
emit(SettingsUpdateSuccess(userAppSettings: result));
6059
} on HtHttpException catch (e) {
61-
emit(SettingsUpdateFailure(e.message));
60+
emit(SettingsUpdateFailure(e.message, userAppSettings: state.userAppSettings));
6261
} catch (e) {
63-
emit(SettingsUpdateFailure('An unexpected error occurred: $e'));
62+
emit(SettingsUpdateFailure('An unexpected error occurred: $e', userAppSettings: state.userAppSettings));
6463
}
6564
}
6665

6766
Future<void> _onSettingsBaseThemeChanged(
6867
SettingsBaseThemeChanged event,
6968
Emitter<SettingsState> emit,
7069
) async {
71-
if (state is SettingsLoadSuccess) {
72-
final currentSettings = (state as SettingsLoadSuccess).userAppSettings;
70+
final currentSettings = state.userAppSettings;
71+
if (currentSettings != null) {
7372
final updatedSettings = currentSettings.copyWith(
7473
displaySettings: currentSettings.displaySettings.copyWith(
7574
baseTheme: event.baseTheme,
@@ -83,8 +82,8 @@ class SettingsBloc extends Bloc<SettingsEvent, SettingsState> {
8382
SettingsAccentThemeChanged event,
8483
Emitter<SettingsState> emit,
8584
) async {
86-
if (state is SettingsLoadSuccess) {
87-
final currentSettings = (state as SettingsLoadSuccess).userAppSettings;
85+
final currentSettings = state.userAppSettings;
86+
if (currentSettings != null) {
8887
final updatedSettings = currentSettings.copyWith(
8988
displaySettings: currentSettings.displaySettings.copyWith(
9089
accentTheme: event.accentTheme,
@@ -98,8 +97,8 @@ class SettingsBloc extends Bloc<SettingsEvent, SettingsState> {
9897
SettingsFontFamilyChanged event,
9998
Emitter<SettingsState> emit,
10099
) async {
101-
if (state is SettingsLoadSuccess) {
102-
final currentSettings = (state as SettingsLoadSuccess).userAppSettings;
100+
final currentSettings = state.userAppSettings;
101+
if (currentSettings != null) {
103102
final updatedSettings = currentSettings.copyWith(
104103
displaySettings: currentSettings.displaySettings.copyWith(
105104
fontFamily: event.fontFamily,
@@ -113,8 +112,8 @@ class SettingsBloc extends Bloc<SettingsEvent, SettingsState> {
113112
SettingsTextScaleFactorChanged event,
114113
Emitter<SettingsState> emit,
115114
) async {
116-
if (state is SettingsLoadSuccess) {
117-
final currentSettings = (state as SettingsLoadSuccess).userAppSettings;
115+
final currentSettings = state.userAppSettings;
116+
if (currentSettings != null) {
118117
final updatedSettings = currentSettings.copyWith(
119118
displaySettings: currentSettings.displaySettings.copyWith(
120119
textScaleFactor: event.textScaleFactor,
@@ -128,8 +127,8 @@ class SettingsBloc extends Bloc<SettingsEvent, SettingsState> {
128127
SettingsFontWeightChanged event,
129128
Emitter<SettingsState> emit,
130129
) async {
131-
if (state is SettingsLoadSuccess) {
132-
final currentSettings = (state as SettingsLoadSuccess).userAppSettings;
130+
final currentSettings = state.userAppSettings;
131+
if (currentSettings != null) {
133132
final updatedSettings = currentSettings.copyWith(
134133
displaySettings: currentSettings.displaySettings.copyWith(
135134
fontWeight: event.fontWeight,
@@ -143,8 +142,8 @@ class SettingsBloc extends Bloc<SettingsEvent, SettingsState> {
143142
SettingsLanguageChanged event,
144143
Emitter<SettingsState> emit,
145144
) async {
146-
if (state is SettingsLoadSuccess) {
147-
final currentSettings = (state as SettingsLoadSuccess).userAppSettings;
145+
final currentSettings = state.userAppSettings;
146+
if (currentSettings != null) {
148147
final updatedSettings = currentSettings.copyWith(
149148
language: event.language,
150149
);

lib/settings/bloc/settings_state.dart

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,79 @@
11
part of 'settings_bloc.dart';
22

33
sealed class SettingsState extends Equatable {
4-
const SettingsState();
4+
const SettingsState({this.userAppSettings});
5+
6+
/// The current user application settings. Null if not loaded or unauthenticated.
7+
final UserAppSettings? userAppSettings;
58

69
@override
7-
List<Object?> get props => [];
10+
List<Object?> get props => [userAppSettings];
811
}
912

1013
/// {@template settings_initial}
1114
/// The initial settings state.
1215
/// {@endtemplate}
13-
final class SettingsInitial extends SettingsState {}
16+
final class SettingsInitial extends SettingsState {
17+
/// {@macro settings_initial}
18+
const SettingsInitial({super.userAppSettings});
19+
}
1420

1521
/// {@template settings_load_in_progress}
1622
/// State indicating that user settings are being loaded.
1723
/// {@endtemplate}
18-
final class SettingsLoadInProgress extends SettingsState {}
24+
final class SettingsLoadInProgress extends SettingsState {
25+
/// {@macro settings_load_in_progress}
26+
const SettingsLoadInProgress({super.userAppSettings});
27+
}
1928

2029
/// {@template settings_load_success}
2130
/// State indicating that user settings have been successfully loaded.
2231
/// {@endtemplate}
2332
final class SettingsLoadSuccess extends SettingsState {
2433
/// {@macro settings_load_success}
25-
const SettingsLoadSuccess({required this.userAppSettings});
26-
27-
/// The loaded user application settings.
28-
final UserAppSettings userAppSettings;
29-
30-
@override
31-
List<Object?> get props => [userAppSettings];
34+
const SettingsLoadSuccess({required super.userAppSettings});
3235
}
3336

3437
/// {@template settings_load_failure}
3538
/// State indicating that loading user settings failed.
3639
/// {@endtemplate}
3740
final class SettingsLoadFailure extends SettingsState {
3841
/// {@macro settings_load_failure}
39-
const SettingsLoadFailure(this.errorMessage);
42+
const SettingsLoadFailure(this.errorMessage, {super.userAppSettings});
4043

4144
/// The error message describing the failure.
4245
final String errorMessage;
4346

4447
@override
45-
List<Object?> get props => [errorMessage];
48+
List<Object?> get props => [errorMessage, userAppSettings];
4649
}
4750

4851
/// {@template settings_update_in_progress}
4952
/// State indicating that user settings are being updated.
5053
/// {@endtemplate}
5154
final class SettingsUpdateInProgress extends SettingsState {
5255
/// {@macro settings_update_in_progress}
53-
const SettingsUpdateInProgress({required this.userAppSettings});
54-
55-
/// The user application settings being updated.
56-
final UserAppSettings userAppSettings;
57-
58-
@override
59-
List<Object?> get props => [userAppSettings];
56+
const SettingsUpdateInProgress({required super.userAppSettings});
6057
}
6158

6259
/// {@template settings_update_success}
6360
/// State indicating that user settings have been successfully updated.
6461
/// {@endtemplate}
6562
final class SettingsUpdateSuccess extends SettingsState {
6663
/// {@macro settings_update_success}
67-
const SettingsUpdateSuccess({required this.userAppSettings});
68-
69-
/// The updated user application settings.
70-
final UserAppSettings userAppSettings;
71-
72-
@override
73-
List<Object?> get props => [userAppSettings];
64+
const SettingsUpdateSuccess({required super.userAppSettings});
7465
}
7566

7667
/// {@template settings_update_failure}
7768
/// State indicating that updating user settings failed.
7869
/// {@endtemplate}
7970
final class SettingsUpdateFailure extends SettingsState {
8071
/// {@macro settings_update_failure}
81-
const SettingsUpdateFailure(this.errorMessage);
72+
const SettingsUpdateFailure(this.errorMessage, {super.userAppSettings});
8273

8374
/// The error message describing the failure.
8475
final String errorMessage;
8576

8677
@override
87-
List<Object?> get props => [errorMessage];
78+
List<Object?> get props => [errorMessage, userAppSettings];
8879
}

0 commit comments

Comments
 (0)