OpenContacts/lib/lifecycle_event_handler.dart

30 lines
764 B
Dart
Raw Permalink Normal View History

2024-01-27 10:39:33 -04:00
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;
}
}
}