title: Navigator.push is not working with setState in flutter
body: <p>Navigator.push is not working with <code>setState</code>.</p>
  <p>Once I removed the setState in the <code>retry()</code> function then it works but I want to use the setState inside the <code>retry</code> function.</p>
  <pre class="lang-dart prettyprint-override"><code>import 'package:covid_19/screens/home.dart';
  import 'package:covid_19/viewmodel/home_view_model.dart';
  import 'package:flutter/material.dart';
  
  void main() =&gt; runApp(MyAppError());
  
  class MyAppError extends StatefulWidget {
    @override
    _MyAppErrorState createState() =&gt; _MyAppErrorState();
  }
  
  class _MyAppErrorState extends State&lt;MyAppError&gt; {
    bool _loading = false;
    final GlobalKey&lt;ScaffoldState&gt; _scaffoldKey = new GlobalKey&lt;ScaffoldState&gt;();
  
    @override
    Widget build(BuildContext context) {
      return _loading ? CircularProgressIndicator() : MaterialApp(
        home: Scaffold(
            key: _scaffoldKey,
            body: Builder(
                  builder:(context)=&gt; 
                SafeArea(
                  child: Container(
                    margin: EdgeInsets.all(10),
                    child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Text(
                        &quot;No internet found. Check your connection&quot;,
                        textAlign: TextAlign.center,
                      ),  
                      FlatButton(
                        child: Text('Retry'),
                        onPressed: retry,
                      )
                    ],
                  ),
                ),
              ),
            ),
        )
      );
    }
  
    Future&lt;void&gt; retry() async{
      setState(() {
        _loading = true;
      });
      print('retrying...');
      HomeViewModel homeViewModel = HomeViewModel();
      homeViewModel.onAppStart().then((_){
        print('pushing');
        Navigator.pushReplacement(_scaffoldKey.currentContext, MaterialPageRoute(builder: (context)=&gt; Home(data : homeViewModel.data)));
      }).catchError((e){
        setState(() {
          _loading = false;
        });
      });
      
    }
  }
  
  </code></pre>
  <p>logs when the retry button clicked without <code>setState</code>:</p>
  <pre><code>retrying...
  pushing... 
  and navigate to Home()
  </code></pre>
  <p>logs when the retry button clicked with <code>setState</code>:</p>
  <pre><code>retrying...
  pushing... 
  and nothing happens
  </code></pre>