title: How to get user id from Firebase Auth in Flutter?
body: <p>I want to save user-related data in Firestore by assigning user id to a document as a field. </p>
  
  <p><strong>How to get user id from Firebase Auth?</strong> </p>
  
  <p><strong>Or is there a better way to store user data in Firestore?</strong></p>
  
  <p>I couldn't get user id from Firebase Auth in this way (the Text(_userId) returns _userId == null error): </p>
  
  <pre><code>String _userId;
    ...
  
    @override
    Widget build(BuildContext context) {
      FirebaseAuth.instance.currentUser().then((user) {
        _userId = user.uid;
      });
  
      return new Scaffold(
        appBar: new AppBar(
          title: new Text("App bar"),
        ),
        body: new Text(_userId),
      );
    }
  </code></pre>