title: Flutter Widgets Binding Observer
body: <p>In Flutter,I want to go back to the page I left the app from. But when I try to back, it always navigates to LoginPage. For example,I have 3 page.LoginPage,WorkoutPage,ProgressPage.Login page is my launcher.  When I am on ProgressPage, I leave the app. But when I resume,it navigates Login Page.I used this code in login page.</p>
  
  <p>Login Page</p>
  
  <pre><code>  class ProgressTabState extends State with WidgetsBindingObserver{
    AppLifecycleState state;
    @override
    void initState() {
    // TODO: implement initState
    super.initState();
  
    WidgetsBinding.instance.addObserver(this);
    }
  
    @override
    void dispose() {
    // TODO: implement dispose
    super.dispose();
    WidgetsBinding.instance.removeObserver(this);
    }
  
    @override
    void didChangeAppLifecycleState(AppLifecycleState appLifecycleState) {
    // TODO: implement didChangeAppLifecycleState
    super.didChangeAppLifecycleState(state);
    state = appLifecycleState;  
    }
  </code></pre>
  
  <p>in login page I use this code to navigate to MainTab.</p>
  
  <pre><code>  Navigator.push(
      context,
      MaterialPageRoute(
        builder: (_) {
          return MainTabs();
        },
      ),
    ); 
  </code></pre>
  
  <p>in Main tabs I have Tabbarviews with two page. Workoutpage and ProgressPage. This is Workout Page.</p>
  
  <pre><code> class WorkoutTabState extends State &lt;WorkoutTab&gt; {
   @override
   void initState() {
  // TODO: implement initState
   super.initState();
   }
  
   @override
   void dispose() {
    // TODO: implement dispose
     super.dispose();
  
    }
  
    @override
    Widget build(BuildContext context)  {
  
     // TODO: implement build
     return Scaffold(
         body:Text("Workout Page"),
      );
     }
  </code></pre>
  
  <p>Progress Page</p>
  
  <pre><code>    class ProgressTabState extends State with WidgetsBindingObserver{
  
      AppLifecycleState state;
  
      @override
      void initState() {
       // TODO: implement initState
       super.initState();
  
       WidgetsBinding.instance.addObserver(this);
       }
  
       @override
       void dispose() {
       // TODO: implement dispose
       super.dispose();
       WidgetsBinding.instance.removeObserver(this);
       }
  
  
       @override
       void didChangeAppLifecycleState(AppLifecycleState appLifecycleState) {
       // TODO: implement didChangeAppLifecycleState
       super.didChangeAppLifecycleState(state);
       state = appLifecycleState;
  
  
  
        }
  
  
        @override
        Widget build(BuildContext context) {
        return Scaffold(
  
        body:Text("Progress Page"));
  
  
        }}
  </code></pre>