title: Flutter - user model is NULL even after binding it using bindStream
body: <p>I am trying to add a shopping cart functionality to my app wherein the UserModel contains fields name,email,uid and cart. I have created an AuthController extends GetxController where I have created userModel isntance and then in setInitialScreen function I am binding the userModel to a function &quot;listenToUser()&quot; which is a Stream and recieves snapshot from firestore and maps it to the userModel. But on printing the userModel I see null being printed in the console meaning the data is not getting binded which is causing problems as i can't access the cart stored in the userModel.
  <strong>Edit</strong>: <strong>I saw that I need to attach obs to userModel like: Rx&lt;model.User&gt;? userModel = model.User().obs; but there's a problem that all the fields in this model are required and how can i pass these field values when they have not yet been intialized.</strong>
  Console output: <a href="https://i.stack.imgur.com/eMvRW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eMvRW.png" alt="Console showing null for userModel" /></a></p>
  <p>AuthController code</p>
  <pre><code>class AuthController extends GetxController {
    static AuthController instance = Get.find();
    late Rx&lt;User?&gt; _user;
    Rx&lt;model.User&gt;? userModel;
  
    @override
    void onReady() {
      super.onReady();
      _user = Rx&lt;User?&gt;(firebaseAuth.currentUser);
      _user.bindStream(firebaseAuth.authStateChanges());
      ever(_user, _setInitialScreen);
    }
  
    _setInitialScreen(User? user) {
      if (user == null) {
        Get.offAll(() =&gt; LoginScreen());
      } else {
        userModel?.bindStream(listenToUser());
        Get.offAll(() =&gt; const HomeScreen());
        print(userModel); // PRINTING USER MODEL TO SEE IF ITS NULL
        // userModel?.bindStream(listenToUser());
      }
    }
  
    // registering the user
    void registerUser(String username, String email, String password) async {
      try {
        if (username.isNotEmpty &amp;&amp; email.isNotEmpty &amp;&amp; password.isNotEmpty) {
          // save our user to our auth and firebase firestore
          UserCredential cred = await firebaseAuth.createUserWithEmailAndPassword(
            email: email,
            password: password,
          );
          model.User user = model.User(
              name: username, email: email, uid: cred.user!.uid, cart: []);
          await firestore
              .collection('users')
              .doc(cred.user!.uid)
              .set(user.toJson());
        } else {
          Get.snackbar(
            'Error Creating Account',
            'Please enter all the fields',
          );
        }
      } catch (e) {
        Get.snackbar(
          'Error Creating Account',
          e.toString(),
        );
      }
    }
  
    void loginUser(String email, String password) async {
      try {
        if (email.isNotEmpty &amp;&amp; password.isNotEmpty) {
          await firebaseAuth.signInWithEmailAndPassword(
              email: email, password: password);
          print('log success');
        } else {
          Get.snackbar(
            'Error Logging in',
            'Please enter all the fields',
          );
        }
      } catch (e) {
        Get.snackbar(
          'Error Logging in',
          e.toString(),
        );
      }
    }
  
    updateUserData(Map&lt;String, dynamic&gt; data) {
      print(&quot;UPDATED&quot;);
      firestore.collection('users').doc(_user.value?.uid).update(data);
    }
  
    Stream&lt;model.User&gt; listenToUser() =&gt; firestore
        .collection('users')
        .doc(_user.value?.uid)
        .snapshots()
        .map((snapshot) =&gt; model.User.fromSnap(snapshot));
  }
  
  </code></pre>
  <p>User Model code:</p>
  <pre><code>
  
  class User {
    // static const UID = &quot;uid&quot;;
    // static const NAME = &quot;name&quot;;
    // static const EMAIL = &quot;email&quot;;
  
    String uid;
    String name;
    String email;
    List&lt;CartItemModel&gt; cart;
  
    User(
        {required this.name,
        required this.email,
        required this.uid,
        required this.cart});
  
    Map&lt;String, dynamic&gt; toJson() =&gt;
        {&quot;name&quot;: name, &quot;email&quot;: email, &quot;uid&quot;: uid, &quot;cart&quot;: cart};
  
    // static User fromSnap(DocumentSnapshot snap) {
    static User fromSnap(DocumentSnapshot snap) {
      var snapshot = snap.data() as Map&lt;String, dynamic&gt;;
      return User(
          name: snapshot['name'],
          email: snapshot['email'],
          uid: snapshot['uid'],
          cart: _convertCartItems(snapshot['cart'] ?? []));
    }
  
    // List&lt;CartItemModel&gt; _convertCartItems(List cartFromDb) {
    static List&lt;CartItemModel&gt; _convertCartItems(List cartFromDb) {
      List&lt;CartItemModel&gt; _result = [];
      // logger.i(cartFromDb.lengt);
      print(cartFromDb.length);
      cartFromDb.forEach((element) {
        _result.add(CartItemModel.fromMap(element));
      });
      return _result;
    }
  }
  </code></pre>
  <p>Also I referred this github for shopping cart functionality but I have made some changes to make it null safe: <a href="https://github.com/Santos-Enoque/flutter-shopping-app/blob/main/lib/controllers/authController.dart" rel="nofollow noreferrer">cart functionality github</a></p>