Skip to content

Commit 9d4fcdd

Browse files
authored
Merge pull request #74 from flutter-news-app-full-source-code/fix-status-feature
Fix status feature
2 parents ca782bb + 48ed29a commit 9d4fcdd

File tree

3 files changed

+27
-29
lines changed

3 files changed

+27
-29
lines changed

lib/app/bloc/app_bloc.dart

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -461,20 +461,13 @@ class AppBloc extends Bloc<AppEvent, AppState> {
461461

462462
// --- POST-CHECK STATE RESOLUTION ---
463463
// If no critical status was found, we resolve the final state.
464-
465-
// For an initial fetch, we transition from configFetching to the correct
466-
// authenticated/anonymous state.
467-
if (!event.isBackgroundCheck) {
468-
final finalStatus = state.user!.appRole == AppUserRole.standardUser
469-
? AppStatus.authenticated
470-
: AppStatus.anonymous;
471-
emit(state.copyWith(remoteConfig: remoteConfig, status: finalStatus));
472-
} else {
473-
// For a background check, the status is already correct (e.g., authenticated).
474-
// We just need to update the remoteConfig in the state silently.
475-
// The status does not need to change, preventing a disruptive UI rebuild.
476-
emit(state.copyWith(remoteConfig: remoteConfig));
477-
}
464+
// This logic applies to both initial fetches (transitioning from
465+
// configFetching) and background checks (transitioning from a state
466+
// like underMaintenance back to a running state).
467+
final finalStatus = state.user!.appRole == AppUserRole.standardUser
468+
? AppStatus.authenticated
469+
: AppStatus.anonymous;
470+
emit(state.copyWith(remoteConfig: remoteConfig, status: finalStatus));
478471
} on HttpException catch (e) {
479472
print(
480473
'[AppBloc] Failed to fetch AppConfig (HttpException) for user ${state.user?.id}: ${e.runtimeType} - ${e.message}',

lib/app/services/app_status_service.dart

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ class AppStatusService with WidgetsBindingObserver {
3030
required BuildContext context,
3131
required Duration checkInterval,
3232
required AppEnvironment environment,
33-
}) : _context = context,
34-
_checkInterval = checkInterval,
35-
_environment = environment {
33+
}) : _context = context,
34+
_checkInterval = checkInterval,
35+
_environment = environment {
3636
// Immediately register this service as a lifecycle observer.
3737
WidgetsBinding.instance.addObserver(this);
3838
// Start the periodic checks.
@@ -62,18 +62,16 @@ class AppStatusService with WidgetsBindingObserver {
6262
_timer = Timer.periodic(_checkInterval, (_) {
6363
// In demo mode, periodic checks are not needed as there's no backend.
6464
if (_environment == AppEnvironment.demo) {
65-
print(
66-
'[AppStatusService] Demo mode: Skipping periodic check.',
67-
);
65+
print('[AppStatusService] Demo mode: Skipping periodic check.');
6866
return;
6967
}
7068
print(
7169
'[AppStatusService] Periodic check triggered. Requesting AppConfig fetch.',
7270
);
7371
// Add the event to the AppBloc to fetch the latest config.
74-
_context
75-
.read<AppBloc>()
76-
.add(const AppConfigFetchRequested(isBackgroundCheck: true));
72+
_context.read<AppBloc>().add(
73+
const AppConfigFetchRequested(isBackgroundCheck: true),
74+
);
7775
});
7876
}
7977

@@ -92,9 +90,7 @@ class AppStatusService with WidgetsBindingObserver {
9290

9391
// We are only interested in the 'resumed' state.
9492
if (state == AppLifecycleState.resumed) {
95-
print(
96-
'[AppStatusService] App resumed. Requesting AppConfig fetch.',
97-
);
93+
print('[AppStatusService] App resumed. Requesting AppConfig fetch.');
9894
// When the app comes to the foreground, immediately trigger a check.
9995
// This is crucial for catching maintenance mode that was enabled
10096
// while the app was in the background.

lib/app/view/app.dart

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,10 @@ class _AppViewState extends State<_AppView> {
238238
fontFamily: null,
239239
),
240240
themeMode: state.themeMode,
241-
localizationsDelegates: AppLocalizations.localizationsDelegates,
241+
localizationsDelegates: const [
242+
...AppLocalizations.localizationsDelegates,
243+
...UiKitLocalizations.localizationsDelegates,
244+
],
242245
supportedLocales: AppLocalizations.supportedLocales,
243246
locale: state.locale,
244247
home: const MaintenancePage(),
@@ -262,7 +265,10 @@ class _AppViewState extends State<_AppView> {
262265
fontFamily: null,
263266
),
264267
themeMode: state.themeMode,
265-
localizationsDelegates: AppLocalizations.localizationsDelegates,
268+
localizationsDelegates: const [
269+
...AppLocalizations.localizationsDelegates,
270+
...UiKitLocalizations.localizationsDelegates,
271+
],
266272
supportedLocales: AppLocalizations.supportedLocales,
267273
locale: state.locale,
268274
home: const UpdateRequiredPage(),
@@ -289,7 +295,10 @@ class _AppViewState extends State<_AppView> {
289295
fontFamily: null,
290296
),
291297
themeMode: state.themeMode,
292-
localizationsDelegates: AppLocalizations.localizationsDelegates,
298+
localizationsDelegates: const [
299+
...AppLocalizations.localizationsDelegates,
300+
...UiKitLocalizations.localizationsDelegates,
301+
],
293302
supportedLocales: AppLocalizations.supportedLocales,
294303
locale: state.locale,
295304
home: const StatusPage(),

0 commit comments

Comments
 (0)