1

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);
godopetza
  • 67
  • 1
  • 8
  • hey from the package of image_picker you can see this https://pub.dev/packages/image_picker_for_web#limitations-on-the-web-platform for web platform limitation – Stanly Jan 08 '23 at 11:48

0 Answers0