Я создаю программу для сохранения фотографии в хранилище Firebase, а затем беру URL и записываю его в базу данных Firebase.
File sampleImage;
String changePhoto;
Future getImage() async {
var tempImage = await ImagePicker.pickImage(source: ImageSource.gallery);
setState(() {
sampleImage = tempImage;
});
}
Future getUrl(name) async
{
final ref = FirebaseStorage.instance.ref().child(name);
changePhoto = await ref.getDownloadURL();
print(changePhoto);
return changePhoto;
}
Widget submitButton() {
final name = productName.text;
return RaisedButton(
textColor: Colors.white,
color: Color(0xffd50000),
child: Text("Add"),
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30.0)),
onPressed: () {
final StorageReference firebaseStorageRef =
FirebaseStorage.instance.ref().child(name);
final StorageUploadTask task =
firebaseStorageRef.putFile(sampleImage);
getUrl(name);
_bloc.submit(changePhoto);
print(5);
Navigator.of(context).pop();
});
}
Но у меня проблема с
changePhoto = await ref.getDownloadURL ();
, потому что ref.getDownloadURL () возвращает динамическую переменную.Я пытался использовать
Future loadPhoto(name)
{
final StorageReference firebaseStorageRef =
FirebaseStorage.instance.ref().child(name);
final StorageUploadTask task =
firebaseStorageRef.putFile(sampleImage);
}
onPressed: () {
loadPhoto(name).then((snapshot){
final ref = FirebaseStorage.instance.ref().child(name);
changePhoto = snapshot.ref.getDownloadURL();
print(changePhoto);
_bloc.submit(changePhoto);
print(5);
Navigator.of(context).pop();
});
Но это не работает.В чем моя ошибка или как я могу получить снимок?Любая помощь очень ценится.