storing user data in firebase

Issue

i want to add user data to the firebase using firestore ,i am watching toutial form udemy but due to firestore update i face this error(The method ‘document’ isn’t defined for the type ‘CollectionReference’.
Try correcting the name to the name of an existing method, or defining a method named ‘document’.)

 await FirebaseFirestore.instance
                .collection('users')
                .document(userCredential.user?.uid)//The method 'document' isn't defined for the type 'CollectionReference'.
    Try correcting the name to the name of an existing method, or defining a method named 'document'.
                .setData({
              'username': username,
              'email': email,
            });

Solution

document is changed to doc and setDocument to set

Here is correct code:

await FirebaseFirestore.instance
                .collection('users')
                .doc(userCredential.user?.uid)
                .set({
                  'username': username,
                  'email': email,
                });

Answered By – Hrvoje ÄŒukman

Answer Checked By – David Marino (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *