Unsupported operation: _Namespace while using dart io on web Unsupported operation: _Namespace while using dart io on web dart dart

Unsupported operation: _Namespace while using dart io on web


dart:io can not be used in web projects. dart:html has some limited file API (limited to what the browser allows). Dart in the browser can not do anything the browser does not provide.

(Not sure why Günter didn't put this as an answer...)


if (kIsWeb) {  image = Image.network(pickedFile.path);} else {  image = Image.file(File(pickedFile.path));}

The answer is in the documentationhttps://pub.dev/packages/image_picker


use https://pub.dev/packages/image_picker library.

in dart file :-

import 'dart:io';

for pick the image use following code :-

_imgFromGallery() async {   final temp = (await ImagePicker().                 getImage(source:ImageSource.camera,imageQuality:                  80));   imageForSendToAPI = await temp.readAsBytes();   setState(() {});  }

This method will take image from desktop.

here imageForSendToAPI will give you uint8list,which you can pass to API.

for showing the selected file use :

Image.memory(imageForSendToAPI)

for sending to API don't use multipart, just pass like below:-

data = {"profile_image":imageForsendToAPI.toString();}