You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
HMG_QLine/lib/utilities/lifecycle_handler.dart

52 lines
1.3 KiB
Dart

import 'package:flutter/widgets.dart';
import 'package:hmg_qline/config/dependency_injection.dart';
import 'package:hmg_qline/services/logger_service.dart';
import 'package:hmg_qline/utilities/enums.dart';
class LifecycleHandler extends WidgetsBindingObserver {
final void Function()? onResumed;
final void Function()? onPaused;
final void Function()? onDetached;
final void Function()? onInactive;
final void Function()? onHidden;
LifecycleHandler({
this.onResumed,
this.onPaused,
this.onDetached,
this.onInactive,
this.onHidden,
});
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
LoggerService loggerService = getIt.get<LoggerService>();
loggerService.logInfo("[didChangeAppLifecycleState] : ${state.toString()}");
switch (state) {
case AppLifecycleState.resumed:
onResumed?.call();
break;
case AppLifecycleState.paused:
onPaused?.call();
break;
case AppLifecycleState.inactive:
onInactive?.call();
break;
case AppLifecycleState.detached:
onDetached?.call();
break;
case AppLifecycleState.hidden:
onHidden?.call();
break;
}
}
void register() {
WidgetsBinding.instance.addObserver(this);
}
void unregister() {
WidgetsBinding.instance.removeObserver(this);
}
}