【问题标题】:Error: Unsupported operation: _Namespace when using image_picker flutter web错误:不支持的操作:使用 image_picker 时的 _Namespace
【发布时间】:2021-08-02 17:08:38
【问题描述】:

当我在 Flutter Web 中使用 image_picker 时 得到问题'错误:不支持的操作:命名空间 在 Object.throw [as throw] (http://localhost:56308/dart_sdk.js:5334:11) 在 Function.get _namespace [as _namespace] (http://localhost:56308/dart_sdk.js:55299:17) 在 io._File.new.lengthSync (http://localhost:56308/dart_sdk.js:53158:59)'

这在 android 中工作正常,在图像选择窗口中打开并且图像已成功预览 但不能在颤振网络中工作 在网络案例中,图像选择窗口打开但图像未获取。

这是我的图像选择器代码...

最终选择器 = ImagePicker(); var imag = await picker.getImage(source: oursource);

var imageFile = File(imag.path);

【问题讨论】:

    标签: flutter flutter-web imagepicker


    【解决方案1】:

    使用这个:

    kIsWeb
    ? Image.network(selectedImage.path)
    : Image.file(File(selectedImage.path)),
    

    我希望工作(为时已晚;))

    【讨论】:

      【解决方案2】:

      不要使用来自 'dart:io' 的文件,而是使用 html.File
      示例:

      import 'dart:html' as html;
      
      var imageFile = html.File(image.path.codeUnits, image.path);
      

      要获取路径,请使用 imageFile.name

      这对我有用。

      【讨论】:

        猜你喜欢
        • 2014-03-10
        • 2021-10-01
        • 2021-12-23
        • 2015-02-16
        • 1970-01-01
        • 2021-12-26
        • 1970-01-01
        • 2017-03-30
        • 1970-01-01
        相关资源
        最近更新 更多