title: How to navigate to another page on load in Flutter
body: <p>I want to navigate to the login page if there is no logged in user, otherwise display the homepage. I thought of calling <code>Navigator.of(context).push()</code> conditionally inside the build method but that triggers an exception. Is there some method I'm missing that I can override? </p>
  
  <p>Update to add the Homepage widget</p>
  
  <pre><code>class HomePage extends StatelessWidget {
  final AppUser user;
  
  const HomePage({Key key, this.user}) : super(key: key);
  
  @override
  Widget build(BuildContext context) {
  return Scaffold(
      appBar: AppBar(
        title: Text('Rera Farm'),
        actions: &lt;Widget&gt;[
          PopupMenuButton(
            itemBuilder: (BuildContext context) {
              return &lt;PopupMenuEntry&gt;[
                PopupMenuItem(
                  child: ListTile(
                    title: Text('Settings'),
                    onTap: () {
                      Navigator.pop(context);
                      Navigator.push(context,
                          MaterialPageRoute(builder: (BuildContext context) 
                        =&gt; SettingsPage()
                      ));
                    },
                  ),
                ),
              ];
            },
          )
        ],
      ),
      body: _buildBody(context));
  }
  </code></pre>
  
  <p>And the container</p>
  
  <pre><code>class HomePageContainer extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
   return new StoreConnector&lt;AppState, _ViewModel&gt;(
     converter: _ViewModel.fromStore,
     builder: (BuildContext context, _ViewModel vm) {
       return HomePage(
        user: vm.user,
       );
     },
   );
   }
  }
  </code></pre>