I'm new in flutter and I don't know how to write in a particular document(userId) in firestore.
I want my database is like: users(collection) |-> userId |->name : Richie
Here is my attempt:
Future<FirebaseUser> user =FirebaseAuth.instance.currentUser();
DocumentReference ref =Firestore.instance.collection('users').document(user.uid);
Please help
You need to await to get the FirebaseUser before you can access the id. 
I created a simple function below demonstrating this for you. 
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;
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With