Unhandled Exception: Invalid argument: Instance of 'Future<String>'

454 views Asked by At

When i run this it gives an error saying Unhandled Exception: Invalid argument: Instance of 'Future<String>'

String username = FirebaseAuth.instance.currentUser!.displayName.toString();

void _uploadImage() async {
setState(() {
  _isUploading = true;
});
final ref = FirebaseStorage.instance
    .ref()
    .child("posts")
    .child(FirebaseAuth.instance.currentUser!.uid + '.jpg');
await ref.putFile(_pickedImage).whenComplete(() {
  setState(() {
    _isUploading = false;
  });
});
await FirebaseFirestore.instance
    .collection("posts")
    .doc(FirebaseAuth.instance.currentUser!.uid)
    .set({'username': username, 'imageUrl': ref.getDownloadURL()});
}

I want to upload the username to firestore along with the imageUrl but i cannot find a way to get the username of the user

0

There are 0 answers