KEVIN
KEVIN

Reputation: 69

Refresh homescreen in flutter when user comes back to the app after leaving the application..App is still in RAM of the phone

I have a single screen application which .For now, When a user has left the application for less than a minute or so, the app is still on the phones ram and the user can pick from where he left.

I want a feature where, when the user comes back to the app screen after leaving the app, the screen can refresh because contents change..

Upvotes: 2

Views: 2187

Answers (1)

Kaushik Chandru
Kaushik Chandru

Reputation: 17772

Assuming that you are using a stateful widget add a widgetbinding observer to it

class _yourClassState extends State<YourClass>
    with WidgetsBindingObserver {
// Here you can override initstate, build etc
}

Now widgetBindingObserver will also let you override didChangeAppLifeCycleState which will allow you to capture the state of the app.

@override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    switch (state) {
      case AppLifecycleState.resumed:
        print("app in resumed from background"); //you can add your codes here
        break;
      case AppLifecycleState.inactive:
        print("app is in inactive state");
        break;
      case AppLifecycleState.paused:
        print("app is in paused state");
        break;
      case AppLifecycleState.detached:
        print("app has been removed");
        break;
    }
}

Upvotes: 4

Related Questions