title: flutter :NoSuchMethodError: The getter 'id' was called on null. Receiver: null Tried calling: id
body: <p>When I register a new user or even log in, the user's data is not stored in currentUser, so when I want to use it to save the post data in a new collection with name posts, I get this error.NoSuchMethodError: The getter 'id' was called on null. Receiver: null Tried calling: id .
  alsol i get this Exception:
  throw new NoSuchMethodError.withInvocation(this, invocation);</p>
  <p>my register code :</p>
  <pre><code>  Future&lt;void&gt; registerWithEmailAndPassword(
        String email, String password, username) async {
      print(&quot;registering now&quot;);
      try {
        final authResult = await FirebaseAuth.instance
            .createUserWithEmailAndPassword(email: email, password: password);
        var _uid = authResult.user.uid;
        // DocumentSnapshot doc = await usersRef.doc(user.id).get();
        print(&quot;this is userid: $_uid&quot;);
        createUserInFirestore(authResult, username);
  
     
        return _userFromFirebase(authResult.user);
      } catch (e) {
        print(e.toString());
        return null;
      }
    }
  
    Future&lt;void&gt; logout() async {
      await FirebaseAuth.instance.signOut();
    }
  
      Future&lt;void&gt;createUserInFirestore(authResult, username) async {
  
     
      var User user= FirebaseAuth.instance.currentUser;
      
      DocumentSnapshot doc = await usersRef.doc(user.uid).get();
  
      if (!doc.exists) {
  collection
        usersRef.doc(user.uid).set({
          &quot;userid&quot;: user.uid,
          &quot;username&quot;: username,
          &quot;photoUrl&quot;: user.photoURL,
          &quot;email&quot;: user.email,
          &quot;displayName&quot;: user.displayName,
          &quot;bio&quot;: &quot;&quot;,
          &quot;timestamp&quot;: timestamp
        });
  
        doc = await usersRef.doc(user.uid).get();
      }
  
      currentUser = Users.fromDocument(doc);
    }
  </code></pre>
  <p>and her for post</p>
  <pre><code>
  
  
    createPostInFirestore(
        {String mediaUrl, String location, String description}) {
      postsRef
          .doc(widget.currentUser.id)
          .collection(&quot;userPosts&quot;)
          .doc(postId)
          .set({
        &quot;postId&quot;: postId,
        &quot;ownerId&quot;: widget.currentUser.id,
        &quot;username&quot;: widget.currentUser.username,
        &quot;mediaUrl&quot;: mediaUrl,
        &quot;description&quot;: description,
        &quot;location&quot;: location,
        &quot;timestamp&quot;: timestamp,
        &quot;likes&quot;: {},
      });
    }
  
    handleSubmit() async {
      setState(() {
        isUploading = true;
      });
      await compressImage();
      String mediaUrl = await uploadImage(file);
      createPostInFirestore(
        mediaUrl: mediaUrl,
        location: locationController.text,
        description: captionController.text,
      );
      setState(() {
        file = null;
        isUploading = false;
        postId = Uuid().v4();
      });
    }
  
  </code></pre>
  <p>and I use this model to save currentUser datat</p>
  <pre><code>import 'package:cloud_firestore/cloud_firestore.dart';
  
  class Users {
    final String id;
    final String username;
    final String email;
    final String photoUrl;
    final String displayName;
    final String bio;
  
    Users({
      this.id,
      this.username,
      this.email,
      this.photoUrl,
      this.displayName,
      this.bio,
    });
  
    factory Users.fromDocument(DocumentSnapshot doc) {
      return Users(
        id: doc['userid'],
        email: doc['email'],
        username: doc['username'],
        //photoUrl: doc['photoUrl'],
        //displayName: doc['displayName'],
        bio: doc['bio'],
      );
    }
  }
  
  </code></pre>