ente/lib/ui/lifecycle_event_handler.dart

31 lines
790 B
Dart
Raw Normal View History

2021-06-29 10:31:27 +00:00
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
class LifecycleEventHandler extends WidgetsBindingObserver {
final AsyncCallback? resumeCallBack;
final AsyncCallback? suspendingCallBack;
2021-06-29 10:31:27 +00:00
LifecycleEventHandler({
this.resumeCallBack,
this.suspendingCallBack,
});
@override
Future<void> didChangeAppLifecycleState(AppLifecycleState state) async {
switch (state) {
case AppLifecycleState.resumed:
if (resumeCallBack != null) {
await resumeCallBack!();
2021-06-29 10:31:27 +00:00
}
break;
case AppLifecycleState.inactive:
case AppLifecycleState.paused:
case AppLifecycleState.detached:
if (suspendingCallBack != null) {
await suspendingCallBack!();
2021-06-29 10:31:27 +00:00
}
break;
}
}
}