Flutter: Unhandled Exception: NoSuchMethodError: The getter 'id' was called on null. Receiver: null Tried calling: id

后端 未结 2 1249
面向向阳花
面向向阳花 2021-01-07 02:50

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 do

相关标签:
2条回答
  • 2021-01-07 03:06

    go to payment.dart and enable the option of the checkout page

    and disable the native option

    0 讨论(0)
  • 2021-01-07 03:16

    currentUser is null because you didn't initialize the class. For example:

      saveUserInfoToFireStore() async {
        currentUser = User(); //initialize
        preferences = await SharedPreferences.getInstance();
        DocumentSnapshot documentSnapshot = await usersReference.document(currentUser.id).get();
    

    Of course the above code still wont work, because id is equal to null. If the document id in your database is equal to the user uid, then do the following:

    User loggedInUser;
    
      saveUserInfoToFireStore() async {
         var user = FirebaseAuth.instance.currentUser();
         loggedInUser = User(id : user.uid);
        preferences = await SharedPreferences.getInstance();
        DocumentSnapshot documentSnapshot = await usersReference.document(loggedInUser.id).get();
    

    So here you get the uid of the user from Firebase Authentication and then since you are using optional named parameter, you can initialize the User class with the id property and use it inside the document() method.

    0 讨论(0)
提交回复
热议问题