class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
// This variable will tell you whether the application is in foreground or not.
bool _isInForeground = true;
@override
void initState() {
super.initState();
WidgetsBinding.instance!.addObserver(this);
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
super.didChangeAppLifecycleState(state);
_isInForeground = state == AppLifecycleState.resumed;
}
@override
void dispose() {
WidgetsBinding.instance!.removeObserver(this);
super.dispose();
}
@override
Widget build(BuildContext context) => Scaffold();
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
switch (state) {
case AppLifecycleState.resumed:
//다시돌아왔을때
print("app in resumed");
break;
case AppLifecycleState.inactive:
//나갔을때
print("app in inactive");
break;
case AppLifecycleState.paused:
//나간거 인식하고 앱 멈춤
print("app in paused");
break;
case AppLifecycleState.detached:
print("app in detached");
break;
}
// super.didChangeAppLifecycleState(state);
// _isInForeground = state == AppLifecycleState.resumed;
}