forked from Nexus/nexus
pause sync when app is backgrounded
This commit is contained in:
parent
b6ee5aec64
commit
9f0b80072d
4 changed files with 40 additions and 1 deletions
18
lib/controllers/app_paused.dart
Normal file
18
lib/controllers/app_paused.dart
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import "package:flutter/widgets.dart";
|
||||
import "package:flutter_riverpod/flutter_riverpod.dart";
|
||||
|
||||
class AppPausedController extends Notifier<bool> {
|
||||
@override
|
||||
bool build() {
|
||||
final listener = AppLifecycleListener(
|
||||
onPause: () => state = true,
|
||||
onResume: () => state = false,
|
||||
);
|
||||
ref.onDispose(listener.dispose);
|
||||
return WidgetsBinding.instance.lifecycleState == .paused;
|
||||
}
|
||||
|
||||
static final provider = NotifierProvider<AppPausedController, bool>(
|
||||
AppPausedController.new,
|
||||
);
|
||||
}
|
||||
Loading…
Reference in a new issue