I have a function to pick images in my webapp using the image_picker package, The code works when on localhost but once the webapp is live it wont allow image picker function to work, how can I fix this?
My code looks like this.
Future<void> pickImage() async {
if (!kIsWeb) {
final imagePicker = ImagePicker();
XFile? imageFile =
await imagePicker.pickImage(source: ImageSource.gallery);
if (imageFile != null) {
// Upload the image
var selected = File(imageFile.path);
setState(() {
_pickedImage = selected;
});
} else {
// print('No image selected');
}
} else if (kIsWeb) {
final imagePicker = ImagePicker();
XFile? imageFile =
await imagePicker.pickImage(source: ImageSource.gallery);
if (imageFile != null) {
// Upload the image
var f = await imageFile.readAsBytes();
setState(() {
webImage = f;
_pickedImage = File('a');
});
} else {
// print('No image selected');
}
} else {
// print('Something went wrong');
}
}
I have also initialized the following fields
File? _pickedImage;
Uint8List webImage = Uint8List(8);