Home > front end >  Flutter: Image Picker Package. Limiting to only JPEG, JPG, & PNG Files to be Selectable
Flutter: Image Picker Package. Limiting to only JPEG, JPG, & PNG Files to be Selectable

Time:02-25

I'm thinking about using the image picker package for my app. The thing is that I only want the user to be allowed to select images that are of type JPEG, JPG, or PNG. Is there a way to go about doing this?

Thank You.

CodePudding user response:

The file_picker package gives you this option already:


FilePickerResult? result = await FilePicker.platform.pickFiles(
      type: FileType.custom,
      allowMultiple: false,
      allowedExtensions: ['jpg', 'jpeg', 'png'],
    );

CodePudding user response:

If I understand correctly you would want to show a message if the user selects an image with an extension other than the one you want? If so you could just grab whatever the path of the image is. Run some if else statements and check if the file extension is any of the ones you want. If you need some help getting the path of the images from image_picker let me know.

  • Related