0

Whenever I click on pick image from gallery using image_picker: ^0.8.6+1 plugin, it opens up the gallery and when I select any image, the app simply crashes with the following message in the console: "Lost connection to device."

Here is the report I'm getting when Runner stops.

Last Exception Backtrace:
0   CoreFoundation                      0x7ff80042889b __exceptionPreprocess + 226
1   libobjc.A.dylib                     0x7ff80004dba3 objc_exception_throw + 48
2   CoreFoundation                      0x7ff800437ab8 +[NSObject(NSObject) instanceMethodSignatureForSelector:] + 0
3   CoreFoundation                      0x7ff80042cd71 ___forwarding___ + 1431
4   CoreFoundation                      0x7ff80042f068 _CF_forwarding_prep_0 + 120
5   image_picker_ios                       0x109b6d5de +[FLTImagePickerMetaDataUtil convertImage:usingType:quality:] + 238 (FLTImagePickerMetaDataUtil.m:86)
6   image_picker_ios                       0x109b6df9a +[FLTImagePickerPhotoAssetUtil saveImageWithMetaData:image:suffix:type:imageQuality:] + 170 (FLTImagePickerPhotoAssetUtil.m:88)
7   image_picker_ios                       0x109b6dc16 +[FLTImagePickerPhotoAssetUtil saveImageWithOriginalImageData:image:maxWidth:maxHeight:imageQuality:] + 566 (FLTImagePickerPhotoAssetUtil.m:57)
8   image_picker_ios                       0x109b749e5 __52-[FLTPHPickerSaveImageToPathOperation processImage:]_block_invoke + 261 (FLTPHPickerSaveImageToPathOperation.m:143)
9   image_picker_ios                       0x109b74af2 __52-[FLTPHPickerSaveImageToPathOperation processImage:]_block_invoke.73 + 130 (FLTPHPickerSaveImageToPathOperation.m:160)
10  Photos                              0x7ff80bb5f7a0 __79-[PHImageManager requestImageDataAndOrientationForAsset:options:resultHandler:]_block_invoke_2 + 150
11  libdispatch.dylib                   0x7ff80013b7fb _dispatch_call_block_and_release + 12
12  libdispatch.dylib                   0x7ff80013ca3a _dispatch_client_callout + 8
13  libdispatch.dylib                   0x7ff80014c32c _dispatch_main_queue_drain + 1338
14  libdispatch.dylib                   0x7ff80014bde4 _dispatch_main_queue_callback_4CF + 31
15  CoreFoundation                      0x7ff800387b1f __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
16  CoreFoundation                      0x7ff800382436 __CFRunLoopRun + 2482
17  CoreFoundation                      0x7ff8003816a7 CFRunLoopRunSpecific + 560
18  GraphicsServices                    0x7ff809cb128a GSEventRunModal + 139
19  UIKitCore                              0x11fa14ad3 -[UIApplication _run] + 994
20  UIKitCore                              0x11fa199ef UIApplicationMain + 123
21  Runner                                 0x102d7c24f main + 63 (AppDelegate.swift:13)
22  dyld_sim                               0x1090b42bf start_sim + 10
23  dyld                                   0x108fff52e start + 462

Here is my flutter doctor

[✓] Flutter (Channel stable, 3.3.10, on macOS 12.6.2 21G320 darwin-x64, locale en-PK)
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.3)
[✓] VS Code (version 1.74.3)
[✓] Connected device (4 available)
[✓] HTTP Host Availability

Here is the the plugins and dart SDK that I have used in my pubspec file

environment:
  sdk: ">=2.12.0 <3.0.0"

image_picker: ^0.8.6+1
google_maps_flutter: ^2.2.3

Here is the code sample:

    try {
      final ImagePicker picker = ImagePicker();
      final image = await picker.pickImage(source: source, imageQuality: 30, maxHeight: 400, maxWidth: 300);
      if (image != null) {
        final cropped = await ImageCropper().cropImage(
          sourcePath: image.path,
          aspectRatio: const CropAspectRatio(ratioX: 1, ratioY: 1),
          compressQuality: 100,
          cropStyle: CropStyle.circle,
          maxHeight: 700,
          maxWidth: 700,
        );

        if (cropped != null) {
          setState(() {
            _selectedFile = File(cropped.path);
          });
        }
      } else {
        setState(() {});
      }
    } catch(e) {
      debugPrint('Error in image picker: $e');
    }

Here is the permission declarations in info.plist file

    <key>NSCameraUsageDescription</key>
    <string>abcAPP needs to access your camera only for scanning the Document and setting-up your Profile.</string>
    <key>NSLocationUsageDescription</key>
    <string>abcAPP needs to access your location to help you while finding your rides nearby you.</string>
    <key>NSLocationWhenInUseUsageDescription</key>
    <string>abcAPP needs to access your location to help you while finding your rides nearby you.</string>
    <key>NSMicrophoneUsageDescription</key>
    <string>abcAPP needs to access your Microphone for recording the video.</string>
    <key>NSPhotoLibraryUsageDescription</key>
    <string>abcAPP needs to access your Photo Library to set-up your Profile.</string>

All the permissions are working fine and after granting the permission, gallery opens up and selecting any image from the gallery crashes the app with no logs in Android studio console.

I have tested this code on simulators as well as real devices but no luck. The same code works fine for Android side but don't know why its was working fine a few weeks ago and not working right now.

And here is output from xcode when I click on any image from gallery: enter image description here

Haris Raza
  • 21
  • 5

1 Answers1

0

After struggling two days I came to know that this issue is fixed in this image_picker_ios: ^0.8.6+6 version. But I don't know why this version was not added in the main "image_picker: ^0.8.6+1". And that's why I have overrided that specific package in pubspec.yaml file under dependency_overrides like this.

dependency_overrides:
 image_picker_ios: ^0.8.6+6

And now it works like a charm :)

Haris Raza
  • 21
  • 5