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);
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.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.