1

I don't know if this is the way to ask this, also I want to achieve this without state management. so here's the code that getting user is from firebase

 final docUsers = FirebaseFirestore.instance.collection('users').doc();

        final userObject = Users(
          id: docUsers.id,
          name: userName,
          email: emailAdress,
          password: password,
        );

        await docUsers.set(userObject.toJson());

        userID = docUsers.id;

userID = docUsers.id; the user id is the global variable here, so I assigned the value to the global variable when the id received. but when it using its shows the value is null, how to achieve this without statemanagement (I meant bloc, provider and like many others. not the "state management").

so how can I achieve that?

pluto
  • 115
  • 8
  • can you check [link1](https://stackoverflow.com/questions/59068260/how-to-make-the-data-from-firestore-in-to-a-global-variable) & [link2](https://stackoverflow.com/questions/67535334/how-to-assign-data-fetched-from-firestore-collection-get-then-method-to) which might help. – Sathi Aiswarya May 27 '22 at 07:45

1 Answers1

2

Could you show how and when your value is NULL?

But this might help:

class MyGlobalVariables {
  static String userId = '123';
}

MyGlobalVariables.userId = 'abc';

print( MyGlobalVariables.userId ); // = abc

It looks like you want to create entries for new users of your App in the database. If this is the case, one would want to use Firebase Authentication for dealing with that:

https://firebase.google.com/docs/auth/

Dabbel
  • 2,468
  • 1
  • 8
  • 25
  • no i want to add a id to user collection . and later to check the user id and the app product id . that's why storing this id; – pluto May 22 '22 at 02:33
  • Well, then storing a variable globally as a static variable as shown above should help? – Dabbel May 22 '22 at 08:55