I am trying to add document to my cloud firestore DB. In this manner.
Future<String> currentlyIn()async{
FirebaseAuth auth = FirebaseAuth.instance;
String fuser = await auth.currentUser();
});
return fuser.uid;
}
Map<String, dynamic> votedown() {
Map<String, dynamic> comdata = <String, dynamic>{
'user_Id':currentlyIn(),
'actual_vote':0,
'voteUp': false,
};
return comdata;
}
DocumentReference storeReference =Firestore.instance.collection('htOne').document('docq');
await storeReference.setData(votedown());
However I get this error anytime I run the code. I need help on how to go about this successfully
E/flutter ( 6263): [ERROR:flutter/shell/common/shell.cc(181)] Dart Error: Unhandled exception:
E/flutter ( 6263): Invalid argument: Instance of 'Future<String>'
E/flutter ( 6263): #0 StandardMessageCodec.writeValue (package:flutter/src/services/message_codecs.dart:353:7)
E/flutter ( 6263): #1 FirestoreMessageCodec.writeValue (file:///C:/NoFlutterPerms/Git/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.7.4/lib/src/firestore_message_codec.dart:38:13)
currentlyIn
returns a Future
. You need to treat it as such.
A Future doesn't automatically convert to the value it completes with.
You can use async
/await
like:
Future<Map<String, dynamic>> votedown() async {
Map<String, dynamic> comdata = <String, dynamic>{
'user_Id': await currentlyIn(),
'actual_vote':0,
'voteUp': false,
};
return comdata;
}
DocumentReference storeReference =Firestore.instance.collection('htOne').document('docq');
await storeReference.setData(await votedown());
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