Skip to content

Instantly share code, notes, and snippets.

@dinko7
Created January 16, 2024 08:50
Show Gist options
  • Save dinko7/acea4fd4690a36213509d831a53f9778 to your computer and use it in GitHub Desktop.
Save dinko7/acea4fd4690a36213509d831a53f9778 to your computer and use it in GitHub Desktop.
Android style app lifecycle awareness mixin for Flutter
import 'package:flutter/material.dart';
mixin AppLifecycleAware<T extends StatefulWidget> on State<T> {
late final AppLifecycleListener _listener;
@override
void initState() {
super.initState();
_listener = AppLifecycleListener(
onDetach: onDetach,
onHide: onHide,
onInactive: onInactive,
onPause: onPause,
onRestart: onRestart,
onResume: onResume,
onShow: onShow,
onStateChange: onStateChange,
);
}
@override
void dispose() {
_listener.dispose();
super.dispose();
}
void onDetach() {}
void onHide() {}
void onInactive() {}
void onPause() {}
void onRestart() {}
void onResume() {}
void onShow() {}
void onStateChange(AppLifecycleState state) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment