小编Zak*_*aru的帖子

每次使用 Flutter/Firebase 按下上传时如何创建唯一的图像 ID?

我正在尝试制作一个图像上传按钮并将其链接到 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)

unique-id dart firebase flutter google-cloud-firestore

4
推荐指数
2
解决办法
2836
查看次数