📅  最后修改于: 2022-03-11 14:48:19.088000             🧑  作者: Mango
class _MyHomePageState extends State with WidgetsBindingObserver {
late AppLifecycleState _notification;
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
setState(() {
_notification = state;
});
}
@override
initState() {
super.initState();
WidgetsBinding.instance!.addObserver(this);
...
}
@override
void dispose() {
WidgetsBinding.instance!.removeObserver(this);
super.dispose();
}
}