Ashwani Kumar
Ashwani Kumar

Reputation: 234

How add data in current user document with flutter using firestore?

Future<DocumentReference> getUserDoc() async {
 final FirebaseAuth _auth = FirebaseAuth.instance;
 final Firestore _firestore = Firestore.instance;

 FirebaseUser user = await _auth.currentUser();
 DocumentReference ref = _firestore.collection('users').document(user.uid);
 return ref;
}

I'm unable to add data in document.

Here is my code to enter data in firestore. Please help, I'm new in flutter

return ref.setData(data);

Error is

The return type 'Future' isn't a 'Future', as defined by the method 'getUserDoc'.dart(return_of_invalid_type)

Upvotes: 0

Views: 2296

Answers (1)

anmol.majhail
anmol.majhail

Reputation: 51316

This should work :

  Future<void> getUserDoc() async {
    final FirebaseAuth _auth = FirebaseAuth.instance;
    final Firestore _firestore = Firestore.instance;

    FirebaseUser user = await _auth.currentUser();
    DocumentReference ref = _firestore.collection('users').document(user.uid);
    return ref.setData({'UID': user.uid});
  }

Upvotes: 2

Related Questions