title: Flutter FutureBuilder and navigation to a different route using Navigator.pushNamed
body: <p>What I'm trying to do is to show a widget with loading status while I'm fetching some info from the web using the http client. Then based on the result to automatically navigate to a different route.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>class Home extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return Scaffold(
          body: SafeArea(
              child: FutureBuilder(
        future: http.get("https://exmaple.com"),
        builder: (BuildContext context, AsyncSnapshot&lt;http.Response&gt; snapshot) {
          switch (snapshot.connectionState) {
            case ConnectionState.none:
              return Text('ConnectionState.none.');
            case ConnectionState.active:
            case ConnectionState.waiting:
              return Text('Awaiting result...');
            case ConnectionState.done:
              if (snapshot.hasError) {
                return Text('Error: ${snapshot.error}');
              } else {
  //              Navigator.pushNamed(context, '/route2');
                return Text('Result: ${snapshot.data.statusCode}');
              }
          }
          return null; // unreachable
        },
      )));
    }
  }
  </code></pre>
  
  <p>The problem is that if I add <code>Navigator.pushNamed(context, '/route2');</code> it will throw an error.</p>
  
  <p>I  understand why it is throwing the error. What I don't know is how to achieve this. All examples that I found showed that navigation happens after some user iteration <code>onPressed</code> .</p>