title: Accessing currentUser data in firebase_auth plugin version 0.2.0
body: <p>In my app, I have a drawer with a <strong>UserAccountsDrawerHeader</strong>, which I feed its properties by simply getting the x property from <strong>FirebaseAuth.instance.currentUser.x</strong> </p>
  
  <p>In the latest <a href="https://pub.dartlang.org/packages/firebase_auth" rel="nofollow noreferrer">firebase_auth 0.2.0</a>  version  , where currentUser() is async. </p>
  
  <p>I have been trying for several hours to store the information of the currently logged user and have not yet reached the correct way to do this. </p>
  
  <p>I understand that I can access them by something like the following:</p>
  
  <pre><code>   Future&lt;String&gt; _getCurrentUserName() async {
    FirebaseUser user = await FirebaseAuth.instance.currentUser();
    return user.displayName;
  }
  </code></pre>
  
  <p>...</p>
  
  <pre><code>new UserAccountsDrawerHeader(accountName: new Text(_getCurrentUserName()))
  </code></pre>
  
  <p>I understand that these code snippets will give type mismatch, but I am just trying to illustrate what I am trying to do. </p>
  
  <p>What am I missing exactly that is preventing me from reaching a solution?</p>
  
  <p><strong>Update</strong></p>
  
  <pre><code>class _MyTabsState extends State&lt;MyTabs&gt; with TickerProviderStateMixin {
    TabController controller;
    Pages _page;
    String _currentUserName;
    String _currentUserEmail;
    String _currentUserPhoto;
    @override
    void initState() {
      super.initState();
      _states();
      controller = new TabController(length: 5, vsync: this);
      controller.addListener(_select);
      _page = pages[0];
    }
  </code></pre>
  
  <p><strong>My method</strong></p>
  
  <p>I just coupled the auth state with my previously implemented TabBar state</p>
  
  <pre><code>   _states() async{
       var user = await FirebaseAuth.instance.currentUser();
       var name = user.displayName;
       var email = user.email;
       var photoUrl = user.photoUrl;
      setState(() {
        this._currentUserName=name;
        this._currentUserEmail=email;
        this._currentUserPhoto=photoUrl;
        _page = pages[controller.index];
      });
    }
  </code></pre>
  
  <p><strong>My Drawer</strong></p>
  
  <pre><code>drawer: new Drawer(
          child: new ListView(
            children: &lt;Widget&gt;[
              new UserAccountsDrawerHeader(accountName: new Text(_currentUserName)  ,
                accountEmail: new Text (_currentUserEmail),
                currentAccountPicture: new CircleAvatar(
                 backgroundImage: new NetworkImage(_currentUserPhoto),
                ),
  </code></pre>
  
  <p>Here is the <strong>exception</strong> I get from the debug console</p>
  
  <pre><code>I/flutter (14926): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
  I/flutter (14926): The following assertion was thrown building MyTabs(dirty, state: _MyTabsState#f49aa(tickers:
  I/flutter (14926): tracking 1 ticker)):
  I/flutter (14926): 'package:flutter/src/widgets/text.dart': Failed assertion: line 207 pos 15: 'data != null': is not
  I/flutter (14926): true.
  I/flutter (14926): Either the assertion indicates an error in the framework itself, or we should provide substantially
  </code></pre>
  
  <p><strong>Update 2:</strong></p>
  
  <p>This is how I modified the google sign in function from the firebase examples:</p>
  
  <pre><code>    Future &lt;FirebaseUser&gt; _testSignInWithGoogle() async {
        final GoogleSignInAccount googleUser = await _googleSignIn.signIn();
        final GoogleSignInAuthentication googleAuth =
        await googleUser.authentication;
  //checking if there is a current user
        var check = await FirebaseAuth.instance.currentUser();
        if (check!=null){
          final FirebaseUser user = check;
          return user;
        }
        else{
        final FirebaseUser user = await _auth.signInWithGoogle(
          accessToken: googleAuth.accessToken,
          idToken: googleAuth.idToken,
        );
        assert(user.email != null);
        assert(user.displayName != null);
        assert(!user.isAnonymous);
        assert(await user.getToken() != null);
  
        return user;
      }
      }
  </code></pre>
  
  <p><strong>Update 3:</strong></p>
  
  <p>My main function</p>
  
  <pre><code>void main() {
        runApp(
            new MaterialApp(
          home: new SignIn(),
          routes: &lt;String, WidgetBuilder&gt;{
            "/SignUp":(BuildContext context)=&gt; new SignUp(),
            "/Login": (BuildContext context)=&gt; new SignIn(),
            "/MyTabs": (BuildContext context)=&gt; new MyTabs()},
  
    ));
  }
  </code></pre>
  
  <p>And then my SignIn contains a google button that when pressed:</p>
  
  <pre><code>onPressed: () {  _testSignInWithGoogle(). //async returns FirebaseUser
                            whenComplete(()=&gt;Navigator.of(context).pushNamed("/MyTabs")
                            );
                          }
  </code></pre>
  
  <p>and the Drawer from update 1 is included within MyTabs build.</p>