Error: Unsupported operation: _Namespace when using image_picker flutter web

Viewed 3423

when im using image_picker in flutter web getting issue 'Error: Unsupported operation: Namespace at Object.throw [as throw] (http://localhost:56308/dart_sdk.js:5334:11) at Function.get _namespace [as _namespace] (http://localhost:56308/dart_sdk.js:55299:17) at io._File.new.lengthSync (http://localhost:56308/dart_sdk.js:53158:59)'

This is working fine in android on image selection window open in and image is successfully previewed but not working in flutter web In web case image selection window open but image not getting.

This is my image picker code...

final picker = ImagePicker(); var imag = await picker.getImage(source: oursource);

var imageFile = File(imag.path);
2 Answers

use this:

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

i hope working (its too late ;) )

Instead of using File from 'dart:io' use html.File
example:

import 'dart:html' as html;

var imageFile = html.File(image.path.codeUnits, image.path);

To get the path, use imageFile.name.

This works for me.

Related