-
-
Save talamaska/89d34999e40b9ca933e7202652f27017 to your computer and use it in GitHub Desktop.
Android style app lifecycle awareness mixin for Flutter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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