title: Flutter Exception : The following NoSuchMethodError was thrown while handling a gesture: The getter 'email' was called on null
body: <p>Flutter is showing me that my loggedInUser is empty/void. But i saved it's value from user in getCurrentUser() method . Now due to that, my code is getting an exception at line 92(The line, which is followed by a comment). The exception is -</p>
  <p>The following NoSuchMethodError was thrown while handling a gesture:
  The getter 'email' was called on null.
  Receiver: null
  Tried calling: email</p>
  <p>//But whenever i use  _auth.currentUser.email in place of loggedInUser, my code runs fine. I don't understand why??</p>
  <p>Please someone help me out, I am new to flutter.</p>
  <p>Here's my code for chatting screen -</p>
  <pre><code>import 'package:firebase_core/firebase_core.dart';
  import 'package:flutter/material.dart';
  import 'package:palabrero_chat_app/constants.dart';
  import 'package:firebase_auth/firebase_auth.dart';
  import 'package:cloud_firestore/cloud_firestore.dart';
  
  class ChatScreen extends StatefulWidget {
  
    static const String id = 'chat_screen';
  
    @override
    _ChatScreenState createState() =&gt; _ChatScreenState();
  }
  
  class _ChatScreenState extends State&lt;ChatScreen&gt; {
  
    final myController = TextEditingController();
    @override
    void dispose() {
      myController.dispose();
      super.dispose();
    }
    // ignore: deprecated_member_use
    final _firestore = Firestore.instance;
    final _auth = FirebaseAuth.instance;
    FirebaseUser loggedInUser;
    String messageText;
  
    @override
    void initState() {
      super.initState();
      Firebase.initializeApp().whenComplete(() {
        print(&quot;completed&quot;);
        setState(() {});
      });
      getCurrentUser();
    }
  
    void getCurrentUser() async {
      try {
        final user = await _auth.currentUser;
        if(user!=null) {
          loggedInUser = user;
        }
      }
      catch (e) {
        print(e);
      }
    }
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          leading: null,
          actions: &lt;Widget&gt;[
            IconButton(
                icon: Icon(Icons.close),
                onPressed: () {
                  _auth.signOut();
                  Navigator.pop(context);
                  //Implement logout functionality
                }),
          ],
          title: Text('⚡️Chat'),
          backgroundColor: Colors.lightBlueAccent,
        ),
        body: SafeArea(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: &lt;Widget&gt;[
              Container(
                decoration: kMessageContainerDecoration,
                child: Row(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: &lt;Widget&gt;[
                    Expanded(
                      child: TextField(
                        onChanged: (value) {
                          messageText = value;
                        },
                        decoration: kMessageTextFieldDecoration,
                      ),
                    ),
                    FlatButton(
                      onPressed: () {
                        getCurrentUser();
                        //messageText + loggedInUser.email
                        _firestore.collection('messages').add({
                          'text' : messageText,
                          'sender' :  loggedInUser.email,   //This line no. 92
                           //If i use  _auth.currentUser.email above, in place of loggedInUser, my code 
                           works. Please explain it to me.
                        });
                      },
                      child: Text(
                        'Send',
                        style: kSendButtonTextStyle,
                      ),
                    ),
                  ],
                ),
              ),
            ],
          ),
        ),
      );
    }
  }
  </code></pre>
  <hr />