Files
syncrow-app/lib/utils/helpers/life_cycle_event_handler.dart
2024-02-17 16:27:27 +03:00

36 lines
1022 B
Dart

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<void> 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.
}
}
}