ente/lib/ui/lifecycle_event_handler.dart

33 lines
792 B
Dart
Raw Normal View History

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