无法使用Flutter 翼在FireBase中预览我的图像...

这是我的Firebase控制台屏幕截图.

enter image description here

以下是图库中的图像拾取器服务的代码

Future<File?> getImageFromGallery() async {
    final pickedFile = await _picker.pickImage(source: ImageSource.gallery);
    if (pickedFile != null) {
      image = File(pickedFile.path);
      return image;
    } else {
      Fluttertoast.showToast(msg: 'Error , No Image Selected');
      return null;
    }
  }

使用事件获取文件,然后上载到Firebase存储:

on<SubmitUserFormDataEvent>((event, emit) async {
      emit(UserFormLoadingState());

     // uploading the picture to firebase storage & get url

      File file = event.profile_image_file;

      String baseName = file.path.split('/').last;

      Reference ref = FirebaseStorage.instance
          .ref()
          .child("profile_images/$baseName"); //generate a unique name

      await ref.putFile(file);
      String imageUrl = await ref.getDownloadURL();
      print(imageUrl);

它已成功上载到Firebase并获取下载URL.如果我点击Chrome中的下载URL,它会自动启动Downlaod,但图像不会显示.这不是我不能将其展示给用户界面的原因.

正在获取下载URL,我无法将图像显示到用户界面.我想像这样预览我的形象.我怎么能做到这一点?

enter image description here

推荐答案

在将文件上传到Firebase存储时添加图像扩展名,如下所示

await ref.putFile(file,
SettableMetadata(
        contentType: "image/jpeg",
      ),
);

Flutter相关问答推荐

自动测试Flutter应用程序进行QA的最佳方法是什么?

为什么我不能看到类音频源在flutter?'

文本未设置在集装箱摆动的中心

Riverpod状态管理-在调用请求时更新用户界面

从超级应用程序启动时,Flutter 小应用程序中未加载资源

在背景图像上排列定位徽标

不要跨同步间隔使用BuildContext

为什么FloatingActionButton未显示

Flutter 附近的连接

在 Flutter 中使用条件语句设置 ImageProvider Object 类型的背景图像

如何从Firebase登录获取用户信息,如电话号码、出生日期和性别

#Flutter/Riverpod - 使用 AsyncNotifier 时是否可以仅调用错误?

为什么 Flutter riverpod 直接分配不起作用但方法可以

在 Android 12+ 中,REST API 调用在 flutter 中非常慢,在 WiFi 中需要 10 秒,而在移动数据中不到一秒

如何制作两个显示相关内容且可编辑的文本字段?

在 flutter 中使用 Firebase 实时数据库数据创建无限滚动效果

Flutter 中父容器顶部的 Gridview 间距额外区域

Flutter 上Denim blue colored颜色 的 colored颜色 矩阵代码是什么?

如何将图像网络装箱到具有边界半径的容器中

如何使用我拥有的 .jks 文件签署我的应用程序