30 lines
764 B
Dart
30 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;
|
||
|
}
|
||
|
}
|
||
|
}
|