Home > Enterprise >  Flutter Image_Picker crash iOS app when open Camera
Flutter Image_Picker crash iOS app when open Camera

Time:09-28

everything works perfect in Android when I open gallery or Camera, but when I try on iOS (emulator and real device) gallery works perfect but as soon as I press the Camera option the app crash without console logs only "Lost connection to device"

 // get image File camera
 _getFromCamera(BuildContext context) async {
   XFile? pickedFile = await ImagePicker().pickImage(
     source: ImageSource.camera,
     maxWidth: 1800,
     maxHeight: 1800,
   );
   File rotatedImage =
       await FlutterExifRotation.rotateAndSaveImage(path: pickedFile!.path);
   if (pickedFile != null) {
     image = rotatedImage;
     //File(pickedFile.path);
     final userId = widget.id;
     widget.bloc.uploadProfilePicture(image, userId);
   }
 }

Then I called the function in a Icon button

TextButton.icon(
                     icon: Icon(
                       Icons.photo_camera,
                       color: Theme.of(context).primaryColor,
                     ),
                     label: Text(
                       AppLocalization.of(context)!
                           .getTranslatedValues("cameraLbl")!,
                       style: TextStyle(
                           color: Theme.of(context).colorScheme.secondary,
                           fontWeight: FontWeight.bold),
                     ),
                     onPressed: () {
                       _getFromCamera(context);
                       Navigator.of(context).pop();
                     },
                   )

CodePudding user response:

You have to add additional permissions inside the info.plist file

Add these entries inside it :

<key>NSPhotoLibraryUsageDescription</key>
<string>Needs PhotoLib access</string>

<key>NSCameraUsageDescription</key>
<string>Needs camera access</string>

To add permissions in flutter application, you need to add permissions in both android manifest and info.plist file.

Also you can use any string inside the string tag , and that string would be shown to the user as why the user needs to give permission.

  • Related