1

This is how open gallery and camera in my flutter application. The problem is, I launch camera first then after I open gallery I'm missing cancel button and title on the top in the navigation bar.

But if exit and relaunch the app and I opened gallery first, I can see the title and cancel button in ios image picker.

File img = await ImagePicker.pickImage(source: ImageSource.gallery);

niks290192
  • 694
  • 1
  • 9
  • 23
Sukendh
  • 103
  • 1
  • 6

2 Answers2

0

You can use this image picker plugin :- https://pub.dartlang.org/packages/multi_image_picker#-readme-tab-

This plugin is based on the original image picker plugin with more features.

niks290192
  • 694
  • 1
  • 9
  • 23
-1

I faced same problem in my application. My solution was:

var imagePicker: UIImagePickerController?

func openCamera() -> Void {
    if UIImagePickerController.isSourceTypeAvailable(.camera) {
        let picker = UIImagePickerController()
        picker.delegate = self
        picker.sourceType = .camera;
        picker.allowsEditing = false
        imagePicker = picker //made this way to avoid forced unwrapping in imagePicker
        self.present(picker, animated: true, completion: nil)
    }
}

func openLibrary() -> Void {
    if UIImagePickerController.isSourceTypeAvailable(.photoLibrary) {
        let picker = UIImagePickerController()
        picker.delegate = self
        picker.sourceType = .photoLibrary;
        picker.allowsEditing = true
        imagePicker = picker
        self.present(picker, animated: true, completion: nil)
    }
}

and then I had to implement this:

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
    imagePicker?.dismiss(animated: true, completion: nil)

    uploadImage(resizeImage) //my function to upload the selected image
    imagePicker = nil
}

func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
    imagePicker?.dismiss(animated: true, completion: nil)
    imagePicker = nil
}

Solution applied to Swift 4.2

Caio Ambrosio
  • 61
  • 1
  • 7