Я пытаюсь загрузить изображение в хранилище firebase, а затем поместить URL-адрес загрузки в хранилище firebase cloud, но значение в базе данных всегда равно null
File image;
String imageUrl;
...
Future<Null> uploadImage() async {
if (image == null) {
imageUrl = defaultImage;
} else {
StorageReference ref = FirebaseStorage.instance.ref().child(filename);
uploadTask = ref.putFile(image);
imageUrl = await (await uploadTask.onComplete).ref.getDownloadURL();
}
}
void _addData() {
Firestore.instance.collection('kajian').add({
"imageUrl": imageUrl,
});
image = null;
imageUrl = null;
}
...
Scaffold(
floatingActionButton: new FloatingActionButton(
onPressed: () {
uploadImage();
_addData();
Navigator.pop(context);
},
child: Icon(Icons.cloud_upload),
),