title: Handling authentication state in Flutter with navigation
body: <p>I'm using Google Sign In to handle user authentication in a Flutter app. This works great for a single-view app (no routing), but as soon as I try to add some routes and manage the routes effectively things get pretty tricky. </p>
  
  <p>Correct me if I'm wrong, but what I think I want is a stateful widget at the top level which controls my signed in variable and auth methods. This top level stateful widget also controls my routing. Here are some snippets from my current setup:</p>
  
  <pre><code>class SignInState extends State&lt;SignIn&gt; {
    GoogleSignInAccount _currentUser;
    ...
  
    Future&lt;Null&gt; _handleSignIn() async {
      try {
        await _googleSignIn.signIn();
      } catch (error) {
        print(error);
      }
    }
  
    Future&lt;Null&gt; _handleSignOut() async {
      _googleSignIn.disconnect();
    } 
  
    @override
    Widget build(BuildContext context) {
      return new MaterialApp(
        title: _pageTitle,
        home: new Home(),
        routes: &lt;String, WidgetBuilder&gt; {
          "/": (BuildContext context) =&gt; new Home(),
          "/settings": (BuildContext context) =&gt; new Settings(),
          "/login": (BuildContext context) =&gt; new Login()
        },
        ...
      );
    }
  }
  </code></pre>
  
  <p>My assumption here is that my state would get passed down into the nested widgets but I'm not seeing the <code>_currentUser</code> variable inside <code>Home()</code> for instance.</p>
  
  <p>In other frameworks you can specify methods to run on route load, it'd be nice if there was an elegant way to check if _currentUser existed before loading a route so that I could push a new route if a user wasn't logged in.</p>
  
  <p>If anyone has experience with combining routing and authentication in Flutter apps I'd really appreciate a step in the right direction. Most tutorials I've found are for one or the other.</p>
  
  <p>Thanks!</p>