如何解决错误:不支持的操作:_Namespace 使用 image_picker flutter web 时
当我在 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);
解决方法
不要使用 'dart:io' 中的文件,而是使用 html.File
例子:
import 'dart:html' as html;
var imageFile = html.File(image.path.codeUnits,image.path);
要获取路径,请使用 imageFile.name。
这对我有用。
,使用这个:
kIsWeb
? Image.network(selectedImage.path)
: Image.file(File(selectedImage.path)),
我希望工作(太晚了;))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。