title: Flutter - How to navigate to another page on an asynchronous value
body: <p>I'm trying to show a splash screen on initial app startup until I have all of the data properly retrieved.  As soon as it's there, I want to navigate to the main screen of the app.</p>
  
  <p>Unfortunately, I can't find a good way to trigger a method that runs that kind of Navigation.</p>
  
  <p>This is the code that I'm using to test this idea. Specifically, I want to run the command <code>Navigator.pushNamed(context, 'home');</code> when the variable <code>shouldProceed</code> becomes true.  Right now, the only way I can think to do it is to display a button that I need to press to trigger the navigation code:</p>
  
  <pre><code>import 'package:flutter/material.dart';
  import 'package:catalogo/src/navigationPage.dart';
  
  class RouteSplash extends StatefulWidget {
    @override
    _RouteSplashState createState() =&gt; _RouteSplashState();
  }
  
  class _RouteSplashState extends State&lt;RouteSplash&gt; {
    ValueNotifier&lt;bool&gt; buttonTrigger;
    bool shouldProceed = false;
  
    _fetchPrefs() async { //this simulates the asynchronous function
      await Future.delayed(Duration(
          seconds:
              1)); // dummy code showing the wait period while getting the preferences
      setState(() {
        shouldProceed = true; //got the prefs; ready to navigate to next page.
      });
    }
  
    @override
    void initState() {
      super.initState();
      _fetchPrefs(); // getting prefs etc.
    }
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        body: Center(
          child: shouldProceed
              ? RaisedButton(
                  onPressed: () {
                    print("entered Main");
                    Navigator.pushNamed(context, 'home'); // &lt;----- I want this to be triggered by shouldProceed directly
                  },
                  child: Text("Continue"),
                )
              : CircularProgressIndicator(), //show splash screen here instead of progress indicator
        ),
      );
    }
  }
  </code></pre>
  
  <p>So, in short, how can I trigger a function that runs the Navigation code when shouldProceed changes?</p>