title: Flutter redirect to a new screen when a condition is true
body: <p>I have a flutter application like</p>
  
  <p>main.dart</p>
  
  <pre><code>import 'package:flutter/material.dart';
  import 'network.dart';
  
  void main() =&gt; runApp(HomePage());
  
  class HomePage extends StatefulWidget {
    @override
    State&lt;StatefulWidget&gt; createState() {
      return _MyAppState();
    }
  }
  
  
  class _MyAppState extends State&lt;HomePage&gt; {
    String _message = '';
    final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
  
    _register() {
      _firebaseMessaging.getToken().then((token) =&gt; print(token));
    }
  
    @override
    void initState() {
      super.initState();
      getMessage();
  
      TestNetwork.checkNetwork().then((val){
            print(val);
      });
    }
  
    void getMessage(){
      _firebaseMessaging.configure(
          onMessage: (Map&lt;String, dynamic&gt; message) async {
        print('on message $message');
        setState(() =&gt; _message = message["notification"]["title"]);
      }, onResume: (Map&lt;String, dynamic&gt; message) async {
        print('on resume $message');
        setState(() =&gt; _message = message["notification"]["title"]);
      }, onLaunch: (Map&lt;String, dynamic&gt; message) async {
        print('on launch $message');
        setState(() =&gt; _message = message["notification"]["title"]);
      });
    }
  
    @override
    Widget build(BuildContext context) {
      // TODO: implement build
      return new MaterialApp(
  
          home: new Scaffold(
            body: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: &lt;Widget&gt;[
                Text("Message: $_message"),
              OutlineButton(
                child: Text("Register My Devices"),
                onPressed: () {
                  _register();
                },
              )
  
            ]),
          ),
        );
  
    }
  }
  </code></pre>
  
  <p>I am calling a network checking functionality from another dart file, so</p>
  
  <p>network.dart</p>
  
  <pre><code>import 'package:http/http.dart' as http;
  import 'dart:async';
  
  class TestNetwork {
  
  static String mainWebServiceURL="http://mydmain.com/webservicepath/";
  
  static Future&lt;bool&gt; checkNetwork() async {
    try{
        Map&lt;String,String&gt; _user = {};
        _user['name'] = "Username";
        final response= await http.post(mainWebServiceURL+'/index.php',
          body: _user,
        );
        if(response.statusCode==200)
          return Future.value(true);
          else
          // I want to redierct to another page in main.dart page
    }
    catch (_) {
      // I want to redierct to another page in main.dart page
    }
  
  }
  
  }
  </code></pre>
  
  <p>So my question is if <code>checkNetwork()</code> function fails or the response is "negative" then I want to redirect / show another page in main.dart or another.</p>