I have set up image picker and it works perfectly in localhost but not at all once deployed to web.
I've looked at the web implementation and I think I have done it as it says there but it still doesn't work so I don't know if I missed something?
My code:
File? _pickedImage;
Uint8List webImage = Uint8List(8);
Future<void> _getFromGallery() async {
if (!kIsWeb) {
final ImagePicker getImage = ImagePicker();
XFile? image = await getImage.pickImage(source: ImageSource.gallery);
if (image != null) {
var selected = File(image.path);
setState(() {
_pickedImage = selected;
});
} else {
const Text('Something went wrong.');
}
} else {
final ImagePicker getImage = ImagePicker();
XFile? image = await getImage.pickImage(source: ImageSource.gallery);
if (image != null) {
var f = await image.readAsBytes();
setState(() {
webImage = f;
_pickedImage = File('a');
});
} else {
const Text('Something went wrong.');
}
}
}
For anyone with the same issue - just had to fun flutter clean then flutter pub get and it worked.