我正在尝试制作一个图像上传按钮并将其链接到 Firebase,这样每次按下按钮时,图像都会发送到 Firebase 存储。以下是我的代码的相关片段:
// Files, and references
File _imageFile;
StorageReference _reference =
FirebaseStorage.instance.ref().child('myimage.jpg');
Future uploadImage() async {
// upload the image to firebase storage
StorageUploadTask uploadTask = _reference.putFile(_imageFile);
StorageTaskSnapshot taskSnapshot = await uploadTask.onComplete;
// update the uploaded state to true after uploading the image to firebase
setState(() {
_uploaded = true;
});
}
// if no image file exists, then a blank container shows - else, it will upload
//the image upon press
_imageFile == null
? Container()
: …Run Code Online (Sandbox Code Playgroud)