2022年6月29日星期三

check app lifecycle paused or resumed state

 hi the answer is to use WidgetsBindingObserver. in your app just add

class _MyScreenState extends State<MyScreen> with WidgetsBindingObserver{}


add the following inside our initState:


WidgetsBinding.instance.addObserver(this);


didChangeAppLifecycleState will be:



@override
     void didChangeAppLifecycleState(AppLifecycleState state) {
     super.didChangeAppLifecycleState(state);
      if (state == AppLifecycleState.paused) {
       // went to Background
         }
       if (state == AppLifecycleState.resumed) {
       // came back to Foreground
       }
    }

沒有留言:

發佈留言