【问题标题】:Flutter form builder package image picker firestore flutterFlutter 表单构建器包图像选择器 Firestore Flutter
【发布时间】:2020-09-23 08:01:50
【问题描述】:

我正在使用 Flutter 表单生成器包中的 FormBuilderImagePicker

我想使用 img 路径,但我不能这样做

sending() async {
var storageimage =
    FirebaseStorage.instance.ref().child('/google/google');
var task = storageimage.putFile();
imgurl = await (await task.onComplete).ref.getDownloadURL();
// await Firestore.instance.collection('twst').add(
//   {
//     'img': imgurl.toString(),
//   },
// );

}

我想将该功能与图像选择器一起使用 但问题是我找不到使用 putfile 的路径

【问题讨论】:

    标签: flutter google-cloud-firestore imagepicker


    【解决方案1】:

    要获取FormBuilderImagePicker的路径,类的toString()方法会打印路径。

    这里是example,说明如何在容器中打印包含路径的 FormBuilderImagePicker 的文本字段。

    然后您需要将图像或文件传递给 putFile 方法。

    也可以使用ImagePickerpickImage类方法获取文件。

    sending() async {
       
        File image;
        try {
          //Get the file from the image picker and store it
          image = await ImagePicker.pickImage(source: ImageSource.gallery);
    
        // Throws error when you don't select any image or when you don't have permissions 
        } on PlatformException catch (e) {
          return;
        }
    
        //Create a reference to the location you want to upload to in firebase
        StorageReference reference = FirebaseStorage.instance.ref().child("/google/google");
    
        //Upload the file to Firebase
        StorageUploadTask uploadTask = reference.putFile(image);
    
        StorageTaskSnapshot taskSnapshot = await uploadTask.onComplete;
    
        // Waits till the file is uploaded then stores the download URL
        String url = await taskSnapshot.ref.getDownloadURL();
    
    } 
    

    【讨论】:

      猜你喜欢
      • 2021-03-19
      • 2020-07-10
      • 2021-03-21
      • 2019-12-18
      • 2021-08-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-11
      • 2020-04-15
      相关资源
      最近更新 更多