title: Flutter: Unhandled Exception: NoSuchMethodError: The getter 'id' was called on null. Receiver: null Tried calling: id
body: <p>I'm having issues setting up signing up with an email and password using Flutter. I got it to sign the new user in and it saves their Firebase authentication info but it doesn't save any profile data to the Firebase Storage section. I'm not sure what I'm doing wrong here, I don't understand why id is null. Some help and guidance would be really appreciated!</p>
  <p>This is the error I got</p>
  <pre><code>Unhandled Exception: NoSuchMethodError: The getter 'id' was called on null.
  Receiver: null
  Tried calling: id
  </code></pre>
  <p>This is from user.dart</p>
  <pre><code>import 'package:cloud_firestore/cloud_firestore.dart';
  
  class User {
    final String id;
    final String profileName;
    final String username;
    final String photoUrl;
    final String url;
    final String email;
    final String bio;
    final String createdAt;
  
    User({
      this.id,
      this.profileName,
      this.username,
      this.photoUrl,
      this.url,
      this.email,
      this.bio,
      this.createdAt,
    });
  
    factory User.fromDocument(DocumentSnapshot doc) {
      return User(
        id: doc.documentID,
        email: doc['email'],
        username: doc['username'],
        photoUrl: doc['photoUrl'],
        url: doc['url'],
        profileName: doc['profileName'],
        bio: doc['bio'],
        createdAt: doc['createdAt'],
      );
    }
  }
  </code></pre>
  <p>This is from Signup.dart</p>
  <p>The error pointed to the usersReference.document line.</p>
  <pre><code>import 'dart:io';
  import 'package:flutter/material.dart';
  import 'package:firebase_auth/firebase_auth.dart';
  import 'package:cloud_firestore/cloud_firestore.dart';
  import 'package:buddiesgram/models/user.dart';
  import 'package:buddiesgram/pages/HomePage.dart';
  import 'package:shared_preferences/shared_preferences.dart';
  
  
  class SignupPage extends StatefulWidget {
  
    static final String id = 'signup_page';
    final DateTime timestamp = DateTime.now();
    User currentUser;
  
    @override
    _SignupPageState createState() =&gt; _SignupPageState();
  }
  
  class _SignupPageState extends State&lt;SignupPage&gt; {
    final  FirebaseAuth auth = FirebaseAuth.instance;
    final _formKey = GlobalKey&lt;FormState&gt;();
    String username, email, password;
    SharedPreferences preferences;
  
    checkIfSignedIn() async {
      auth.onAuthStateChanged.listen((user) {
  
        if (user != null) {
          Navigator.push(context, MaterialPageRoute(builder: (context) =&gt; HomePage()));
        }
      });
  
      @override
      void initState() {
        super.initState();
        this.checkIfSignedIn();
      }
    }
  
    saveUserInfoToFireStore() async {
  
      preferences = await SharedPreferences.getInstance();
      DocumentSnapshot documentSnapshot = await usersReference.document(currentUser.id).get();
  
      if(!documentSnapshot.exists) {
        usersReference.document(currentUser.id).setData({
          &quot;id&quot;: currentUser.id,
          &quot;profileName&quot;: currentUser.profileName,
          &quot;username&quot;: currentUser.username,
          &quot;photoUrl&quot;: currentUser.photoUrl,
          &quot;email&quot;: currentUser.email,
          &quot;bio&quot;: &quot;&quot;,
          &quot;timestamp&quot;: timestamp,
          &quot;talkingTo&quot;: null,
        });
  
        //Write data to local
        //currentUser = currentUser as User;
        //await preferences.setString(&quot;id&quot;, currentUser.id);
        //await preferences.setString(&quot;profileName&quot;, currentUser.profileName);
        //await preferences.setString(&quot;photoUrl&quot;, currentUser.photoUrl);
  
        await followersReference.document(currentUser.id).collection(&quot;userFollowers&quot;).document(currentUser.id).setData({});
  
        documentSnapshot = await usersReference.document(currentUser.id).get();
      }
  
      currentUser = User.fromDocument(documentSnapshot);
    }
  
    signUp() async {
      if(_formKey.currentState.validate()) {
        _formKey.currentState.save();
  
        try{
          AuthResult authResult = await auth.createUserWithEmailAndPassword(email: email, password: password);
          FirebaseUser signedInUser = authResult.user;
          if(signedInUser != null) {
          saveUserInfoToFireStore();
          }
          Navigator.push(context, MaterialPageRoute(builder: (context) =&gt; HomePage()));
        }
        catch(e) {
          print(e);
        }
      }
    }
  </code></pre>
  <p>This is from Timeline.dart</p>
  <p>The error pointed to both of the QuerySnapshot lines from those two methods.</p>
  <pre><code>retrieveTimeLine() async {
      QuerySnapshot querySnapshot = await timelineReference.document(currentUser.id)
          .collection(&quot;timelinePosts&quot;).orderBy(&quot;timestamp&quot;, descending: true).getDocuments();
  
      List&lt;Post&gt; allPosts = querySnapshot.documents.map((document) =&gt; Post.fromDocument(document)).toList();
  
      setState(() {
        this.posts = allPosts;
      });
    }
  
    retrieveFollowings() async {
      QuerySnapshot querySnapshot = await followingReference.document(currentUser.id)
          .collection(&quot;userFollowing&quot;).getDocuments();
  
      setState(() {
        followingsList = querySnapshot.documents.map((document) =&gt; document.documentID).toList();
      });
    }
  </code></pre>
  <p>Please let me know if I left anything out, that may help.</p>