Skip to content

Commit 9cf9420

Browse files
committed
feat(app): implement automated app status checks
- Add AppStatusService for periodic and event-driven status checks - Integrate AppStatusService with AppBloc and GoRouter - Ensure automatic status updates when the app is resumed - Implement proper disposal of AppStatusService to prevent memory leaks
1 parent 9f76151 commit 9cf9420

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lib/app/view/app.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
66
import 'package:flutter_bloc/flutter_bloc.dart';
77
import 'package:flutter_news_app_mobile_client_full_source_code/app/bloc/app_bloc.dart';
88
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';
910
import 'package:flutter_news_app_mobile_client_full_source_code/app/services/demo_data_migration_service.dart';
1011
import 'package:flutter_news_app_mobile_client_full_source_code/authentication/bloc/authentication_bloc.dart';
1112
import 'package:flutter_news_app_mobile_client_full_source_code/l10n/app_localizations.dart';
@@ -132,6 +133,8 @@ class _AppViewState extends State<_AppView> {
132133
late final GoRouter _router;
133134
// Standard notifier that GoRouter listens to.
134135
late final ValueNotifier<AppStatus> _statusNotifier;
136+
// The service responsible for automated status checks.
137+
AppStatusService? _appStatusService;
135138
// Removed Dynamic Links subscription
136139

137140
@override
@@ -140,6 +143,15 @@ class _AppViewState extends State<_AppView> {
140143
final appBloc = context.read<AppBloc>();
141144
// Initialize the notifier with the BLoC's current state
142145
_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+
143155
_router = createRouter(
144156
authStatusNotifier: _statusNotifier,
145157
authenticationRepository: widget.authenticationRepository,
@@ -159,6 +171,8 @@ class _AppViewState extends State<_AppView> {
159171
@override
160172
void dispose() {
161173
_statusNotifier.dispose();
174+
// Dispose the AppStatusService to cancel timers and remove observers.
175+
_appStatusService?.dispose();
162176
// Removed Dynamic Links subscription cancellation
163177
super.dispose();
164178
}

0 commit comments

Comments
 (0)