how can i access the app state variable from custom action?

Hi, I have a custom action called onAppBackground and an app state variable called threadId

Future onAppBackground() async {
  // Add your function code here!
  WidgetsBinding.instance.addObserver(AppLifecycleObserver());
}

class AppLifecycleObserver with WidgetsBindingObserver {
  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    if (state == AppLifecycleState.resumed) {
      // Do something when app is resumed
      print('App is in foreground');
    } else if (state == AppLifecycleState.paused) {
      // Do something when app is paused
      print('App is in background');
    }
  }
}

I am trying to access the app state variable (threadId) inside this custom code. This custom code will be added to main.dart, so I cannot have any argument. Do you have any idea how to access the app state variable?

Thank you!

2
8 replies