[Flutter] AppLifecycleState
flutter: AppLifecycleState.inactive
flutter: AppLifecycleState.paused
flutter: AppLifecycleState.inactive
flutter: AppLifecycleState.resumedclass extends StatefulWidget {
LifeCycle({Key key}): super(key: key);
LifeCycleState createState() => new LifeCycleState();
}
class LifeCycleState extends State<LifeCycle> with WidgetsBindingObserver {
@override
void initState(){
super.initState();
WidgetsBinding.instance.addObserver(this);
}
@override
Widget build(BuildContext context){
return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(
title: new Text(''),
),
body: new Center(
child: new Text(''),
),
),
);
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
switch (state) {
case AppLifecycleState.inactive:
print('AppLifecycleState.inactive');
break;
case AppLifecycleState.paused:
print('AppLifecycleState.paused');
break;
case AppLifecycleState.resumed:
print('AppLifecycleState.resumed');
break;
case AppLifecycleState.suspending:
print('AppLifecycleState.suspending');
break;
}
@override
void dispose(){
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
}Last updated