mirror of
https://github.com/rzuasti/oott.git
synced 2026-07-08 19:21:54 +02:00
Pause polling when screens are off-route or app is backgrounded
PolledValue gains pause()/resume() methods. ScannersStatusCard and NotificationsList now implement RouteAware (didPushNext/didPopNext) and WidgetsBindingObserver to stop API calls and tick timers when the widget is not visible, resuming with an immediate fetch on return. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
838b292456
commit
f75d1ce313
@@ -13,12 +13,14 @@ class PolledValue<T> extends ChangeNotifier {
|
||||
required Duration pollInterval,
|
||||
required Duration staleErrorAfter,
|
||||
}) : _fetch = fetch,
|
||||
_pollInterval = pollInterval,
|
||||
_staleErrorAfter = staleErrorAfter {
|
||||
_load();
|
||||
_pollTimer = Timer.periodic(pollInterval, (_) => _load());
|
||||
}
|
||||
|
||||
final Future<T> Function({CancelToken? cancelToken}) _fetch;
|
||||
final Duration _pollInterval;
|
||||
final Duration _staleErrorAfter;
|
||||
Timer? _pollTimer;
|
||||
CancelToken? _cancelToken;
|
||||
@@ -66,6 +68,18 @@ class PolledValue<T> extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
void pause() {
|
||||
_pollTimer?.cancel();
|
||||
_pollTimer = null;
|
||||
_cancelToken?.cancel();
|
||||
}
|
||||
|
||||
void resume() {
|
||||
if (_disposed) return;
|
||||
_load();
|
||||
_pollTimer = Timer.periodic(_pollInterval, (_) => _load());
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_disposed = true;
|
||||
|
||||
Reference in New Issue
Block a user