@@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
6
6
import 'package:flutter_bloc/flutter_bloc.dart' ;
7
7
import 'package:flutter_news_app_mobile_client_full_source_code/app/bloc/app_bloc.dart' ;
8
8
import 'package:flutter_news_app_mobile_client_full_source_code/app/config/app_environment.dart' ;
9
+ import 'package:flutter_news_app_mobile_client_full_source_code/app/services/app_status_service.dart' ;
9
10
import 'package:flutter_news_app_mobile_client_full_source_code/app/services/demo_data_migration_service.dart' ;
10
11
import 'package:flutter_news_app_mobile_client_full_source_code/authentication/bloc/authentication_bloc.dart' ;
11
12
import 'package:flutter_news_app_mobile_client_full_source_code/l10n/app_localizations.dart' ;
@@ -132,6 +133,8 @@ class _AppViewState extends State<_AppView> {
132
133
late final GoRouter _router;
133
134
// Standard notifier that GoRouter listens to.
134
135
late final ValueNotifier <AppStatus > _statusNotifier;
136
+ // The service responsible for automated status checks.
137
+ AppStatusService ? _appStatusService;
135
138
// Removed Dynamic Links subscription
136
139
137
140
@override
@@ -140,6 +143,15 @@ class _AppViewState extends State<_AppView> {
140
143
final appBloc = context.read <AppBloc >();
141
144
// Initialize the notifier with the BLoC's current state
142
145
_statusNotifier = ValueNotifier <AppStatus >(appBloc.state.status);
146
+
147
+ // Instantiate and initialize the AppStatusService.
148
+ // This service will automatically trigger checks when the app is resumed
149
+ // or at periodic intervals, ensuring the app status is always fresh.
150
+ _appStatusService = AppStatusService (
151
+ context: context,
152
+ checkInterval: const Duration (minutes: 15 ),
153
+ );
154
+
143
155
_router = createRouter (
144
156
authStatusNotifier: _statusNotifier,
145
157
authenticationRepository: widget.authenticationRepository,
@@ -159,6 +171,8 @@ class _AppViewState extends State<_AppView> {
159
171
@override
160
172
void dispose () {
161
173
_statusNotifier.dispose ();
174
+ // Dispose the AppStatusService to cancel timers and remove observers.
175
+ _appStatusService? .dispose ();
162
176
// Removed Dynamic Links subscription cancellation
163
177
super .dispose ();
164
178
}
0 commit comments