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.

Here is my 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<http.Response> 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
      },
    )));
  }
}

```

The problem is that if I add `Navigator.pushNamed(context, '/route2');` it will throw an error.

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 `onPressed` .