title: Flutter + Firebase Throwing Unhandled Exception: This widget has been unmounted Error Using Navigator to change view
body: <p>I have a firebase driven Flutter app that is working but throwing errors.</p>
  <p>What I expected, when the app is open the user has to login using an email and password, if the login succeeds then they are taken the a new view called WelcomeScreen.</p>
  <p>What is happening, the users are being taken to a welcome screen after logging in but I get the following errors</p>
  <pre><code>[VERBOSE-2:ui_dart_state.cc(186)] Unhandled Exception: This widget has been unmounted, so the State no longer has a context (and should be considered defunct).
  Consider canceling any active work during &quot;dispose&quot; or using the &quot;mounted&quot; getter to determine if the State is still active.
  #0      State.context.&lt;anonymous closure&gt; (package:flutter/src/widgets/framework.dart:1088:9)
  #1      State.context (package:flutter/src/widgets/framework.dart:1094:6)
  #2      _AuthScreenState.initState.&lt;anonymous closure&gt; (package:autos_latinos/screens/auth_screen.dart:81:35)
  #3      _rootRunUnary (dart:async/zone.dart:1362:47)
  #4      _CustomZone.runUnary (dart:async/zone.dart:1265:19)
  #5      _CustomZone.runUnaryGuarded (dart:async/zone.dart:1170:7)
  #6      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
  #7      _DelayedData.perform (dart:async/stream_impl.dart:591:14)
  #8      _StreamImplEvents.handleNext (dart:async/stream_impl.dart:706:11)
  #9      _PendingEvents.schedule.&lt;anonymous closur&lt;…&gt;
  </code></pre>
  <p>It seems to be pointing to this part here in my code which I use to track authStateChanges from firebase:</p>
  <pre><code>FirebaseAuth.instance.authStateChanges().listen((User user) {
        if (user == null) {
          print('User is currently signed out!');
          if(AuthScreen.id != '/AuthScreen'){
            Navigator.pushReplacement(context, MaterialPageRoute(builder: (BuildContext context) =&gt; AuthScreen()));
          }else{
            print(&quot;Already on auth screen&quot;);
          }
  
  
        } else {
          //Send to welcome screen
          print('User is signed in!');
          Navigator.pushReplacement(context, MaterialPageRoute(builder: (BuildContext context) =&gt; WelcomeScreen()));
        }
      });
  </code></pre>
  <p>Any Advice on how to prevent this error is much appreciated.</p>