OpenContacts/lib/lifecycle_event_handler.dart
2024-01-27 15:39:33 +01:00

29 lines
764 B
Dart

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
class LifecycleEventHandler extends WidgetsBindingObserver {
final AsyncCallback? resumeCallBack;
final AsyncCallback? suspendingCallBack;
LifecycleEventHandler({
this.resumeCallBack,
this.suspendingCallBack,
});
@override
void didChangeAppLifecycleState(AppLifecycleState state) async {
super.didChangeAppLifecycleState(state);
switch (state) {
case AppLifecycleState.resumed:
await resumeCallBack?.call();
break;
case AppLifecycleState.inactive:
case AppLifecycleState.paused:
case AppLifecycleState.detached:
await suspendingCallBack?.call();
break;
default:
break;
}
}
}