Skip to content

Commit ea3858f

Browse files
committed
feat(app): add demo mode optimizations
- Add environment check to skip periodic app status checks in demo mode - Implement conditional app lifecycle checks based on environment - Update AppStatusService constructor to include AppEnvironment parameter - Modify _AppViewState to pass environment to AppStatusService These changes improve the demo experience by reducing unnecessary reloads and optimizing resource usage when running in demo mode.
1 parent bc894c6 commit ea3858f

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/app/services/app_status_service.dart

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'dart:async';
22

33
import 'package:flutter/material.dart';
44
import 'package:flutter_bloc/flutter_bloc.dart';
5+
import 'package:flutter_news_app_mobile_client_full_source_code/app/config/config.dart';
56
import 'package:flutter_news_app_mobile_client_full_source_code/app/bloc/app_bloc.dart';
67

78
/// {@template app_status_service}
@@ -28,8 +29,10 @@ class AppStatusService with WidgetsBindingObserver {
2829
AppStatusService({
2930
required BuildContext context,
3031
required Duration checkInterval,
32+
required AppEnvironment environment,
3133
}) : _context = context,
32-
_checkInterval = checkInterval {
34+
_checkInterval = checkInterval,
35+
_environment = environment {
3336
// Immediately register this service as a lifecycle observer.
3437
WidgetsBinding.instance.addObserver(this);
3538
// Start the periodic checks.
@@ -42,6 +45,9 @@ class AppStatusService with WidgetsBindingObserver {
4245
/// The interval at which to perform periodic status checks.
4346
final Duration _checkInterval;
4447

48+
/// The current application environment.
49+
final AppEnvironment _environment;
50+
4551
/// The timer responsible for periodic checks.
4652
Timer? _timer;
4753

@@ -54,6 +60,13 @@ class AppStatusService with WidgetsBindingObserver {
5460
_timer?.cancel();
5561
// Create a new periodic timer.
5662
_timer = Timer.periodic(_checkInterval, (_) {
63+
// In demo mode, periodic checks are not needed as there's no backend.
64+
if (_environment == AppEnvironment.demo) {
65+
print(
66+
'[AppStatusService] Demo mode: Skipping periodic check.',
67+
);
68+
return;
69+
}
5770
print(
5871
'[AppStatusService] Periodic check triggered. Requesting AppConfig fetch.',
5972
);
@@ -67,6 +80,14 @@ class AppStatusService with WidgetsBindingObserver {
6780
/// This method is called whenever the application's lifecycle state changes.
6881
@override
6982
void didChangeAppLifecycleState(AppLifecycleState state) {
83+
// In demo mode, we disable the app resume check. This is especially
84+
// useful on web, where switching browser tabs would otherwise trigger
85+
// a reload, which is unnecessary and can be distracting for demos.
86+
if (_environment == AppEnvironment.demo) {
87+
print('[AppStatusService] Demo mode: Skipping app lifecycle check.');
88+
return;
89+
}
90+
7091
// We are only interested in the 'resumed' state.
7192
if (state == AppLifecycleState.resumed) {
7293
print(

lib/app/view/app.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ class _AppViewState extends State<_AppView> {
152152
_appStatusService = AppStatusService(
153153
context: context,
154154
checkInterval: const Duration(minutes: 15),
155+
environment: widget.environment,
155156
);
156157

157158
_router = createRouter(

0 commit comments

Comments
 (0)