Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[image_picker] PlatformException(multiple_request, Cancelled by a second request, null, null) when picking the first default image from the ios simulator #82602

Closed
ShunyaWatanabe opened this issue May 15, 2021 · 71 comments · Fixed by flutter/plugins#6858
Assignees
Labels
customer: crowd Affects or could affect many people, though not necessarily a specific customer. found in release: 2.2 Found to occur in 2.2 found in release: 2.10 Found to occur in 2.10 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: image_picker The Image Picker plugin. P1 High-priority issues at the top of the work list package flutter/packages repository. See also p: labels. platform-ios iOS applications specifically r: fixed Issue is closed as already fixed in a newer version

Comments

@ShunyaWatanabe
Copy link

ShunyaWatanabe commented May 15, 2021

Steps to Reproduce

  1. Run flutter create temp.
  2. Update the files as follows: ShunyaWatanabe/flutter-picker-image-test@3e4feeb
  3. Run flutter run --verbose
  4. Click the button on the bottom right, which is the increment counter
  5. Approve permission
  6. Load different default pictures

Expected results:
Image picker should work on all of the default pictures.

Actual results:
One of them doesn't work, with the error that says PlatformException(multiple_request, Cancelled by a second request, null, null)

If this is the expected result, I'd like to know what the cause is and request better logs for better understanding.

cancelled_by_second_request.mov
Logs
[+4665 ms] flutter: error: PlatformException(multiple_request, Cancelled
by a second request, null, null)
Analyzing temp...
No issues found! (ran in 2.5s)
[✓] Flutter (Channel stable, 2.0.4, on Mac OS X 10.15.7 19H114 darwin-x64,
    locale en-JP)
    • Flutter version 2.0.4 at /Users/shunya_watanabe/development/flutter
    • Framework revision b1395592de (6 weeks ago), 2021-04-01 14:25:01
      -0700
    • Engine revision 2dce47073a
    • Dart version 2.12.2

[✓] Android toolchain - develop for Android devices (Android SDK version
    30.0.3)
    • Android SDK at /Users/shunya_watanabe/Library/Android/sdk
    • Platform android-30, build-tools 30.0.3
    • ANDROID_HOME = /Users/shunya_watanabe/Library/Android/sdk
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6915495)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.3, Build version 12C33
    • CocoaPods version 1.10.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google
      Chrome

[✓] Android Studio (version 4.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6915495)

[✓] VS Code (version 1.56.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.22.0

[✓] Connected device (2 available)
    • iPhone 8 (mobile) • 14C87317-9478-42BE-AEE5-9CC4FF5590BA • ios
      • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
    • Chrome (web)      • chrome                               •
      web-javascript • Google Chrome 90.0.4430.212

• No issues found!
@darshankawar darshankawar added the in triage Presently being triaged by the triage team label May 17, 2021
@darshankawar
Copy link
Member

@ShunyaWatanabe
It'd be great if you could provide a code sample in a single file that we can directly copy paste and run to verify the issue.

Also, take a look at this open similar issue which talks about same exception you are getting, #49780 and see if it resemble your issue.

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 17, 2021
@ShunyaWatanabe
Copy link
Author

@darshankawar
I wish I could do that but in order to use image_picker I need to at least modify 3 files (pubspec.yml, main.dart, and pubspec.lock which is automatically modified) and then a few more files to configure permission for access to the photos.
Please understand that this is the minimum I extracted to reproduce the issue.

Also, thanks for the suggestion. I took a look at #49780, but I'm not sure if they are the same issue.

@no-response no-response bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 17, 2021
@darshankawar
Copy link
Member

@ShunyaWatanabe
Manually picking up changes from the file you shared is time consuming. It'd be great if you could put that file in a github repo and share the link that we can clone and directly run to verify this issue.

Thanks.

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 18, 2021
@ShunyaWatanabe
Copy link
Author

You can clone this repo: https://github.com/ShunyaWatanabe/flutter-picker-image-test

@no-response no-response bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 18, 2021
@darshankawar
Copy link
Member

@ShunyaWatanabe
In your code, I see that you've explicitly added to handle permissions using permission_handler plugin, which is not required. On iOS, app now by default asks for permissions, as shown below:

Screenshot 2021-05-18 at 5 32 56 PM

Above screenshot is from plugin's official repo https://github.com/flutter/plugins/tree/master/packages/image_picker/image_picker/example, wherein, you'll see, no explicit permission is used / handled.

Can you try the same without permission_handler issue and see if you still get same issue ?

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 18, 2021
@ShunyaWatanabe
Copy link
Author

ShunyaWatanabe commented May 23, 2021

I removed permission_handler and tried it again, and the error still occurs.

I also updated the code so you could try it too https://github.com/ShunyaWatanabe/flutter-picker-image-test

@no-response no-response bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 23, 2021
@intoxicated
Copy link

I'm experiencing this as well, when user clicks cancel button getImage does not return anything (expect null here), and when getImage is get called again, it throws this error

@darshankawar
Copy link
Member

darshankawar commented May 24, 2021

Thanks for the updated code sample. Using it and with latest plugin version, I was able to replicate the issue, irrespective of any kind of permission we select and seems to be happening only after selecting particular image, ie, top left image:

Screenshot 2021-05-24 at 12 37 23 PM

flutter: pickedFile: Instance of 'PickedFile'
flutter: pickedFile: Instance of 'PickedFile'
flutter: pickedFile: Instance of 'PickedFile'
flutter: pickedFile: Instance of 'PickedFile'
flutter: pickedFile: Instance of 'PickedFile'
flutter: error: PlatformException(multiple_request, Cancelled by a second request, null, null)
flutter: error: PlatformException(multiple_request, Cancelled by a second request, null, null)
flutter: pickedFile: Instance of 'PickedFile'
flutter: pickedFile: Instance of 'PickedFile'
flutter: pickedFile: Instance of 'PickedFile'
flutter: pickedFile: Instance of 'PickedFile'
flutter: pickedFile: Instance of 'PickedFile'
flutter: pickedFile: Instance of 'PickedFile'


Syncing files to device iPhone 12 Pro Max...
flutter: error: PlatformException(multiple_request, Cancelled by a second request, null, null)
flutter: pickedFile: Instance of 'PickedFile'
flutter: pickedFile: Instance of 'PickedFile'
flutter: pickedFile: Instance of 'PickedFile'
flutter: pickedFile: Instance of 'PickedFile'
flutter: pickedFile: Instance of 'PickedFile'
flutter: error: PlatformException(multiple_request, Cancelled by a second request, null, null)
flutter doctor -v
dhs@Dhss-MacBook-Pro ncflutter % flutter doctor -v
[✓] Flutter (Channel stable, 2.2.0, on Mac OS X 10.15.4 19E2269 darwin-x64,
    locale en-GB)
    • Flutter version 2.2.0 at /Users/dhs/documents/fluttersdk/flutter
    • Framework revision b22742018b (9 days ago), 2021-05-14 19:12:57 -0700
    • Engine revision a9d88a4d18
    • Dart version 2.13.0

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.3, Build version 12C33
    • CocoaPods version 1.10.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] VS Code (version 1.55.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.21.0

[✓] Connected device (4 available)
    • Darshan's iphone (mobile)  • 21150b119064aecc249dfcfe05e259197461ce23 •
      ios            • iOS 14.4.1
    • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729     •
      ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
    • macOS (desktop)            • macos                                    •
      darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
    • Chrome (web)               • chrome                                   •
      web-javascript • Google Chrome 90.0.4430.212

• No issues found!



@darshankawar darshankawar added p: first party p: image_picker The Image Picker plugin. found in release: 2.2 Found to occur in 2.2 has reproducible steps The issue has been confirmed reproducible and is ready to work on and removed in triage Presently being triaged by the triage team labels May 24, 2021
@mostafaAbdelazim
Copy link

is there a stable version we can use for now?

@mono0926
Copy link
Contributor

mono0926 commented Jun 1, 2021

This bug seems to be added at 0.7.5( #3835 ).

0.7.5

  • Fixes an issue where image rotation is wrong when Select Photos chose and image is scaled.
  • Migrate to PHPicker for iOS 14 and higher versions to pick image from the photo library.
  • Implement the limited permission to pick photo from the photo library when Select Photo is chosen.
    https://pub.dev/packages/image_picker/changelog#075

This bug can be avoided by downgrading to image_picker: 0.7.4 at pubspec.yaml.

  image_picker: 0.7.4

@a7medpa
Copy link

a7medpa commented Jun 7, 2021

I have the same issue on v0.8.0+1. Oddly, if I pick any other default image other than the first one (with the bunch of flowers) it doesn't give me the error.

@ydag
Copy link

ydag commented Jun 10, 2021

I have the same issue on v0.8.0+1. Oddly, if I pick any other default image other than the first one (with the bunch of flowers) it doesn't give me the error.

This bug seems to be added at 0.7.5( #3835 ).

0.7.5

  • Fixes an issue where image rotation is wrong when Select Photos chose and image is scaled.
  • Migrate to PHPicker for iOS 14 and higher versions to pick image from the photo library.
  • Implement the limited permission to pick photo from the photo library when Select Photo is chosen.
    https://pub.dev/packages/image_picker/changelog#075

This bug can be avoided by downgrading to image_picker: 0.7.4 at pubspec.yaml.

  image_picker: 0.7.4

Hello @mono0926 and @a7medpa,

This is because there is a known issue to pick HEIC images (the first one is HEIC format) with PHPicker implementation. But it should only affect transcoding on simulators. So we have two options here. Either test with a real device or test with non-HEIC images until Apple solves the issue.

@y-alkhateeb
Copy link

y-alkhateeb commented Jun 16, 2021

The same issue with the last version of image_picker: ^0.8.0+3

PlatformException (PlatformException(multiple_request, Cancelled by a second request, null, null))

[✓] Flutter (Channel stable, 2.2.2, on macOS 11.4 20F71 darwin-arm, locale en)
• Flutter version 2.2.2 at /Users/y.alkhateeb/Documents/dev/sdk/flutter
• Framework revision d79295a (5 days ago), 2021-06-11 08:56:01 -0700
• Engine revision 91c9fc8fe0
• Dart version 2.13.3

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at /Users/y.alkhateeb/Library/Android/sdk
• Platform android-30, build-tools 30.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.5, Build version 12E262
• CocoaPods version 1.10.1

[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)

[✓] IntelliJ IDEA Community Edition (version 2021.1.2)
• IntelliJ at /Applications/IntelliJ IDEA CE.app
• Flutter plugin version 57.0.5
• Dart plugin version 211.7233

[✓] VS Code (version 1.56.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.22.0

[✓] Connected device (2 available)
• iPhone 12 Pro Max (mobile) • 00B2C40E-A430-47D8-8D77-4E556C5A9294 • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-5 (simulator)
• Chrome (web) • chrome • web-javascript • Google Chrome 91.0.4472.101

• No issues found!

@maheshj01
Copy link
Member

Updated triage report for this issue can be found here #82602 (comment)

@cardzap-ewan
Copy link

And reproduces for me with the latest 0.8.5 version and latest Xcode. Fwiw, the first call silently fails (I breakpointed every line of code) and somehow you just end up in the main thread. The second call gives the “cancelled by second request” error. Will post a minimal app which exhibits this behaviour soon(ish).

On 30 Apr 2022, at 12:14, Arda Ilgaz @.***> wrote:  @stuartmorgan it does for me — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.

I wrote a minimal app and...it worked fine with iOS 15.4 simulator and 0.8.5....damn. So it's some interaction with another bit of code? Dunno. Anyway, the code below works fine. So a minimal app doesn't trigger the bug/issue.

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: 'Image bug',
      home: HomePage(title: 'Image bug'),
    );
  }
}

class HomePage extends StatefulWidget {
  const HomePage({Key? key, required this.title}) : super(key: key);
  final String title;
  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  XFile? imageFile;

  Future<void> _pickImage() async {
    XFile? pickedImage;
    try {
      pickedImage = await ImagePicker().pickImage(
        source: ImageSource.gallery,
      );
    } catch (e) {
      if (kDebugMode) print(e);
    }
    setState(() {
      imageFile = pickedImage;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            imageFile == null
                ? const Icon(Icons.image)
                : Image.file(File(imageFile!.path))
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _pickImage,
        tooltip: 'Pick an Image',
        child: const Icon(Icons.image),
      ),
    );
  }
}

@FakharAlyas119
Copy link

Does this reproduce with the latest dependencies (image_picker_ios 0.8.5+)? The last update to the iOS implementation packages fixed some situations where we would incorrectly think that a previous request was still in progress.

yes i am still facing this issue even i update the plugin to latest package

@CAJazzer
Copy link

CAJazzer commented Jun 1, 2022

I can consistently reproduce the problem as follows on my M1 Macbook Pro:

  1. Create a new Flutter (3.01) application and add latest image_picker (0.8.5+3) and other packages required for the demo app - Run the app on ios Simulator and everything works fine (non heic images load correctly)
  2. For me, I need the google_maps_flutter package so I add it and configure it for ios. - Now image_picker no longer works and fails with the PlatformException
  3. Removing the google_maps_flutter and its settings allows the image_picker to work

@jmagman
Copy link
Member

jmagman commented Jun 1, 2022

If you are on a M1 Mac you are likely hitting an iOS simulator Rosetta issue. google_maps does not yet support arm64 simulators, which is why adding it drops you back to Rosetta, exposing iOS simulator bugs. You're hitting #82602 (comment) and #74970 (comment). We have an open issue to update google_maps at #94491 but essentially Apple needs to fix that bug.

However, if you are running on an x64 intel machine, as the originator is, you are not hitting a Rosetta issue. This open GitHub issue is tracking that.

@idkq
Copy link

idkq commented Jun 10, 2022

I was able to get a different error by picking a different image (JPG) from the default ones and updating my Xcode.

File: '/Users/xxxxxxxxxx/Library/Developer/CoreSimulator/Devices/1D3E25DA-803E-447F-A42D-
6BC794318FE9/data/Containers/Data/Application/056DDD20-F362-49F0-B36D-
EE6CF862A38A/tmp/image_picker_37D3019E-1DCC-4366-9098-1DF67424373A-71238-0000B04C05F8D3ED.jpg'
 is empty and cannot be loaded as an image.

I'm using the VERY latest version of Xcode 13.4.1 (therefore latest simulator).

Repro:

1 - Download the example app image_picker
2 - Add google_maps_flutter: ^2.1.5 and google_maps_flutter_web: ^0.3.3 to pubspec.yaml
3 - Using simulator browser, go to google, search for a panda, download the (JPG) image to the gallery. Very important, it has to be a panda ;-)
4 - Run example app. Pick the panda.

Another thing. This is weird - not sure if is related:

Photos app crash when you get Information about picture.

1 - Go to Photos
2 - Click on any photo
3 - Click on Information
4 - Photos App will crash with error MobileSlideShow quit unexpectedly

terminating with uncaught exception of type NSException *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'coordinate spaces don't have a common ancestor'

@maheshj01 maheshj01 removed the platform-host-arm Building on an ARM-based platform label Jul 6, 2022
@maheshj01 maheshj01 changed the title [image_picker] [M1 simulator] PlatformException(multiple_request, Cancelled by a second request, null, null) when picking the first default image from the ios simulator [image_picker] PlatformException(multiple_request, Cancelled by a second request, null, null) when picking the first default image from the ios simulator Jul 6, 2022
@maheshj01
Copy link
Member

Updating the issue since this is reproducible on intel machine too.

@pdkcoder
Copy link
Contributor

pdkcoder commented Jul 7, 2022

I still can see this exception on ^0.8.5+3, iOS simulator

@yareyaredesuyo
Copy link

In iOS simulator, you should avoid using top-left sample photo image, because this image type is heif.

Another photo type is all jpeg, so you should use these photo images.

And you can check photo image type using photo app.

@Matias-Raverta
Copy link

Still happening in version image_picker: ^0.8.6. in IOS simulator.
I was able to see the image info in my first try. After a second try I was never able to get the same behavior again. Uninstalled the app from simulator, cleaned the project, run it and gave permissions again for picker to work.

@jmagman jmagman added P1 High-priority issues at the top of the work list and removed P3 Issues that are less important to the Flutter project labels Dec 14, 2022
@jmagman jmagman self-assigned this Dec 14, 2022
@darshankawar darshankawar added the r: fixed Issue is closed as already fixed in a newer version label Dec 20, 2022
@github-actions
Copy link

github-actions bot commented Mar 4, 2023

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 4, 2023
@flutter-triage-bot flutter-triage-bot bot added the package flutter/packages repository. See also p: labels. label Jul 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
customer: crowd Affects or could affect many people, though not necessarily a specific customer. found in release: 2.2 Found to occur in 2.2 found in release: 2.10 Found to occur in 2.10 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: image_picker The Image Picker plugin. P1 High-priority issues at the top of the work list package flutter/packages repository. See also p: labels. platform-ios iOS applications specifically r: fixed Issue is closed as already fixed in a newer version
Projects
None yet
Development

Successfully merging a pull request may close this issue.