【问题标题】:Image.file is not supported on Flutter Web. How to get image from gallery/camera for the Flutter Web?Flutter Web 不支持 Image.file。如何从 Flutter Web 的图库/相机中获取图像?
【发布时间】:2022-08-18 21:46:30
【问题描述】:

在 Chrome 网络浏览器上运行 Flutter 应用程序时出现以下错误。 我从图库中挑选了一张图片:

  Future getImage() async {
    try {
      final image = await ImagePicker().pickImage(source: ImageSource.gallery);
      if (image == null) {
        return;
      }
      final imageTemp = XFile(image.path);
      setState(() => this._userImage = imageTemp);
    } on PlatformException catch (e) {
      e.stacktrace;
    }
  }

代码:

  dynamic getUserImage() {
    if (_userImage?.path == null) {
      return const Icon(
        Icons.person,
        color: Colors.grey,
        size: 54,
      );
    } else {
      return Image.file(File(_userImage!.path));
    }
  }

图片:

我应该使用或更改什么来从 Web 画廊或相机中挑选图像?

    标签: flutter flutter-web flutter-web-images flutter-image-picker


    【解决方案1】:

    试试Web Image picker 或检查 您正在使用的软件包的网络支持Image Picker

    【讨论】:

      【解决方案2】:

      试试Image.network(image.path),因为浏览器不支持访问用户的文件系统。

      由于 Web 浏览器不提供对其用户文件系统的直接访问,因此该插件提供了 PickedFile 抽象以使访问跨平台统一。

      有关详细信息,请参阅Limitations on the web platform

      【讨论】:

        猜你喜欢
        • 2022-11-22
        • 2021-08-30
        • 1970-01-01
        • 2021-07-16
        • 2020-04-15
        • 2020-02-16
        • 2019-09-16
        • 2020-08-02
        • 2020-09-19
        相关资源
        最近更新 更多