title: Flutter : error is Looking up a deactivated widget's ancestor is unsafe
body: <p>So I am trying to log in using NodeJS in my flutter app, and I am able to log in but when I try to add a circular progress indicator while waiting for backend process to finish when user taps on login button by setting state like,</p>
  <pre><code>setState(() {
       validate = true;
        isLoading = true;       
        });
  </code></pre>
  <p>And then I do after successfully logging in,</p>
  <pre><code>setState(() {
      validate = true;
      isLoading = false;
        });
  </code></pre>
  <p>I am getting this error :</p>
  <pre><code>error is Looking up a deactivated widget's ancestor is unsafe. I/flutter ( 4699): At this point the state of the widget's element tree is no longer stable. I/flutter ( 4699): To safely refer to a widget's ancestor in its dispose() method, save a reference to the ancestor 
  </code></pre>
  <p>And I am unable to navigate to another screen but if I remove setState I am successfully navigating to another screen.</p>
  <p>My code for login button click is as follows. isLoading starts with false and when its true, I show a circular progress indicator.</p>
  <pre><code>Future saveLogInData(BuildContext context) async {
      setState(() {
        isLoading = true;
      });
      final formState = _logInFormKey.currentState;
      if (formState.validate() ) {
        formState.save();
        try {
          Map&lt;String, String&gt; data = {
            &quot;email&quot;: loginEmailController.text,
            &quot;password&quot;: loginPasswordController.text,
          };
          print(&quot;my data is : $data&quot;);
          var response = await networkHandler.post(&quot;user/login&quot;, data);
          print(&quot;statuscode is ${response.statusCode}&quot;);
          if(response.statusCode == 200 || response.statusCode == 201){
            Map&lt;String, dynamic&gt; output = json.decode(response.body);
            print(output['token']);
            setState(() {
              validate = true;
              isLoading = false;
            });
            Navigator.push(
                context,
                MaterialPageRoute(
                    builder: (context) =&gt; Home(
  
                    )));
  
            
          }
  
  
  
          else{
            String output = json.decode(response.body);
            print(&quot;output is ${output}&quot;);
            setState(() {
              validate = false;
              isLoading = false;
  
            });
          }
  
  
  
          // user.sendEmailVerification();
  
        } catch (e) {
          print(&quot;error is $e}&quot;);
        } finally {
  
          isLoading = false;
        }
      } else {
        showDialog(
            context: context,
            builder: (BuildContext context) {
              return AlertDialog(
                title: Text(&quot;Error&quot;),
                content: Text(&quot;Please check your email and password&quot;),
                actions: &lt;Widget&gt;[
                  FlatButton(
                    child: Text(&quot;Close&quot;),
                    onPressed: () {
                      Navigator.of(context).pop();
                    },
                  )
                ],
              );
            });
      }
    }
  </code></pre>