How to get both image or video from gallery in flutter?

Viewed 1649

I want to access the gallery and pick image or video on user choice.

I am building an app where user can upload image or video when they click on the gallery icon. I have used ImagePicker but with ImagePicker I will have to make two separate icon for photo and video. I just want one icon for accessing the gallery and to get video or photo in return.

IconButton(
                  icon: Icon(FontAwesome5.getIconData('file-video')),
                  iconSize: 52.0,
                  onPressed: () =>
                      ImagePicker.pickVideo(source: ImageSource.gallery),
                )
2 Answers

For accessing to camera and video with only on click you have to use extension "camera" from pub.dev not "image_picker".

Use filepicker plugin

enter image description here

FilePickerResult? result = await FilePicker.platform.pickFiles( type: FileType.any , allowCompression: false, );

Write code as i have shown in the image. After getting image/ video i am checking if it ends with .jpg or .png performing crop while in else performing what i want after video is selected.

Related