widgetsbindingobserver flutter code example

Example: widgetsbindingobserver flutter

class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver {  ...  @override  void initState() {    super.initState();    WidgetsBinding.instance.addObserver(this);  }  @override    void dispose() {    super.dispose();  }  @override  void didChangeAppLifecycleState(AppLifecycleState state) {    switch (state) {    case AppLifecycleState.inactive:    print("Inactive");    break;    case AppLifecycleState.paused:    print("Paused");    break;    case AppLifecycleState.resumed:    print("Resumed");    break;    case AppLifecycleState.suspending:    print("Suspending");    break;  }  ...}

Tags:

Misc Example