import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; class LifecycleEventHandler extends WidgetsBindingObserver { final AsyncCallback resumeCallBack; final AsyncCallback suspendingCallBack; final AsyncCallback onPauseCallBack; final AsyncCallback inactiveCallBack; LifecycleEventHandler( {required this.resumeCallBack, required this.suspendingCallBack, required this.onPauseCallBack, required this.inactiveCallBack}); @override Future didChangeAppLifecycleState(AppLifecycleState state) async { switch (state) { case AppLifecycleState.resumed: await resumeCallBack(); break; case AppLifecycleState.inactive: await inactiveCallBack(); break; case AppLifecycleState.paused: await onPauseCallBack(); break; case AppLifecycleState.detached: await suspendingCallBack(); break; case AppLifecycleState.hidden: // TODO: Handle this case. } } }