Repository navigation
[image_picker] Image picker returns null when selecting image from other apps when using singleInstance #76856
Description
Activity
- addedin triagePresently being triaged by the triage teamPresently being triaged by the triage team
on Feb 26, 2021 Hi @DomantasZav
Can you please try a different device? Make sure you're using the latest stable `image_picker: ^0.6.7+22
I can't reproduce it on a Oneplus or Realme devicecode runnable sample
import 'package:flutter/material.dart'; import 'package:image_picker/image_picker.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Material App', theme: ThemeData.dark(), home: Home(), ); } } class Home extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Material App Bar'), ), body: Center( child: Container( child: Text('Hello World'), ), ), floatingActionButton: FloatingActionButton( child: Icon(Icons.add), onPressed: () async { final file = await ImagePicker().getImage( source: ImageSource.gallery, imageQuality: 70, maxWidth: 2048, maxHeight: 2048, ); print(file.path); }, ), ); } }
Printing path of the picked file
D/ActivityThread(19231): pid:19231 tid:19231 doframe Callback I/flutter (19231): /storage/emulated/0/Android/data/com.example.stable_flutter/files/Pictures/scaled_image_picker7560935096891424193.jpg
flutter doctor -v
[✓] Flutter (Channel stable, 1.22.6, on Microsoft Windows [Version 10.0.19042.804], locale en-US) • Flutter version 1.22.6 at C:\Users\Taha\Code\flutter_stable • Framework revision 9b2d32b605 (5 weeks ago), 2021-01-22 14:36:39 -0800 • Engine revision 2f0af37152 • Dart version 2.10.5 [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3) • Android SDK at C:\Users\Taha\Code\SDK • Platform android-30, build-tools 30.0.3 • ANDROID_HOME = C:\Users\Taha\Code\SDK • Java binary at: C:\Users\Taha\Code\android-studio\jre\bin\java • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01) • All Android licenses accepted. [!] Android Studio (version 4.1.0) • Android Studio at C:\Users\Taha\Code\android-studio ✗ Flutter plugin not installed; this adds Flutter specific functionality. ✗ Dart plugin not installed; this adds Dart specific functionality. • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01) [✓] VS Code (version 1.53.2) • VS Code at C:\Users\Taha\AppData\Local\Programs\Microsoft VS Code • Flutter extension version 3.19.0 [✓] Connected device (2 available) • IN2011 (mobile) • c9d8ee0c • android-arm64 • Android 11 (API 30) • Android SDK built for x86 (mobile) • emulator-5554 • android-x86 • Android 10 (API 29) (emulator) ! Doctor found issues in 1 category.Thank you
- addedwaiting for responseThe Flutter team cannot make further progress on this issue until the original reporter respondsThe Flutter team cannot make further progress on this issue until the original reporter responds
on Feb 26, 2021 Found the issue:
It only happens on android devices and iflaunchModeinAndroidManifestis set tosingleInstance
The error I provided was caused by something else.
So there is no indication of error. It just returns null.Reacted by delbyze- removedwaiting for responseThe Flutter team cannot make further progress on this issue until the original reporter respondsThe Flutter team cannot make further progress on this issue until the original reporter responds
on Mar 1, 2021 - changed the title
[-][image_picker] Image picker returns null when selecting image from Google Photos[/-][+][image_picker] Image picker returns null when selecting image from Google Photos with launchMode="singleInstance" [/+]on Mar 2, 2021 Hi @DomantasZav
Thanks for the details, I can reproduce it withsingleIntancelogs
Launching lib/main.dart on IN2011 in debug mode... package:triage/main.dart ✓ Built build/app/outputs/flutter-apk/app-debug.apk. W/DisplayEventDispatcher(12154): dispatcher 0x764c0b6fb0 ~ ignoring unknown event type 0x6d746f6e W/DisplayEventDispatcher(12154): dispatcher 0x75fc09fed0 ~ ignoring unknown event type 0x6d746f6e Connecting to VM Service at ws://127.0.0.1:51314/6OwUI-aX26c=/ws D/ViewRootImpl[MainActivity](12154): windowFocusChanged hasFocus=false inTouchMode=true W/DisplayEventDispatcher(12154): dispatcher 0x764c0b6fb0 ~ ignoring unknown event type 0x6d746f6e W/DisplayEventDispatcher(12154): dispatcher 0x75fc09fed0 ~ ignoring unknown event type 0x6d746f6e D/ActivityThread(12154): pid:12154 tid:12154 doframe Callback D/OpScreenModeManager(12154): setRefreshRate parent io.flutter.embedding.android.FlutterView{1f9461f VFE...... ........ 0,0-1080,2355} parent width 1080 parent height 2355 mRatio 1.2 D/OpScreenModeManager(12154): setRefreshRate view io.flutter.embedding.android.FlutterSurfaceView{595c5be V.E...... ........ 0,0-1080,2355} viewRate 1 width 1080 height 2355 D/OpScreenModeManager(12154): setRefreshRate parent io.flutter.embedding.android.FlutterView{1f9461f VFE...... ........ 0,0-1080,2355} parent width 1080 parent height 2355 mRatio 1.2 D/OpScreenModeManager(12154): setRefreshRate view io.flutter.embedding.android.FlutterSurfaceView{595c5be V.E...... ........ 0,0-1080,2355} viewRate 1 width 1080 height 2355 D/DecorView(12154): onWindowFocusChangedFromViewRoot hasFocus: true, DecorView@480458[MainActivity] D/ViewRootImpl[MainActivity](12154): windowFocusChanged hasFocus=true inTouchMode=true D/OpScreenModeManager(12154): setRefreshRate parent io.flutter.embedding.android.FlutterView{1f9461f VFE...... ........ 0,0-1080,2355} parent width 1080 parent height 2355 mRatio 1.2 D/OpScreenModeManager(12154): setRefreshRate view io.flutter.embedding.android.FlutterSurfaceView{595c5be V.E...... ........ 0,0-1080,2355} viewRate 1 width 1080 height 2355 W/DisplayEventDispatcher(12154): dispatcher 0x75fc09fed0 ~ ignoring unknown event type 0x6d746f6e W/DisplayEventDispatcher(12154): dispatcher 0x764c0b6fb0 ~ ignoring unknown event type 0x6d746f6e D/ViewRootImpl[MainActivity](12154): windowFocusChanged hasFocus=false inTouchMode=true W/DisplayEventDispatcher(12154): dispatcher 0x764c0b6fb0 ~ ignoring unknown event type 0x6d746f6e W/DisplayEventDispatcher(12154): dispatcher 0x75fc09fed0 ~ ignoring unknown event type 0x6d746f6e D/DecorView(12154): onWindowFocusChangedFromViewRoot hasFocus: true, DecorView@480458[MainActivity] D/ViewRootImpl[MainActivity](12154): windowFocusChanged hasFocus=true inTouchMode=true D/ViewRootImpl[MainActivity](12154): windowFocusChanged hasFocus=false inTouchMode=true D/ActivityThread(12154): pid:12154 tid:12154 doframe Callback E/flutter (12154): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: NoSuchMethodError: The getter 'path' was called on null. E/flutter (12154): Receiver: null E/flutter (12154): Tried calling: path �[38;5;244mE/flutter (12154): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)�[39;49m �[38;5;248mE/flutter (12154): #1 Home.build.<anonymous closure>�[39;49m package:triage/main.dart E/flutter (12154): <asynchronous suspension> �[38;5;248mE/flutter (12154): #2 Home.build.<anonymous closure> (package:triage/main.dart)�[39;49m package:triage/main.dart �[38;5;244mE/flutter (12154): #3 _InkResponseState._handleTap�[39;49m package:flutter/…/material/ink_well.dart �[38;5;244mE/flutter (12154): #4 _InkResponseState.build.<anonymous closure>�[39;49m package:flutter/…/material/ink_well.dart �[38;5;244mE/flutter (12154): #5 GestureRecognizer.invokeCallback�[39;49m package:flutter/…/gestures/recognizer.dart �[38;5;244mE/flutter (12154): #6 TapGestureRecognizer.handleTapUp�[39;49m package:flutter/…/gestures/tap.dart �[38;5;244mE/flutter (12154): #7 BaseTapGestureRecognizer._checkUp�[39;49m package:flutter/…/gestures/tap.dart �[38;5;244mE/flutter (12154): #8 BaseTapGestureRecognizer.handlePrimaryPointer�[39;49m package:flutter/…/gestures/tap.dart �[38;5;244mE/flutter (12154): #9 PrimaryPointerGestureRecognizer.handleEvent�[39;49m package:flutter/…/gestures/recognizer.dart �[38;5;244mE/flutter (12154): #10 PointerRouter._dispatch�[39;49m package:flutter/…/gestures/pointer_router.dart �[38;5;244mE/flutter (12154): #11 PointerRouter._dispatchEventToRoutes.<anonymous closure>�[39;49m package:flutter/…/gestures/pointer_router.dart �[38;5;244mE/flutter (12154): #12 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:377:8)�[39;49m �[38;5;244mE/flutter (12154): #13 PointerRouter._dispatchEventToRoutes�[39;49m package:flutter/…/gestures/pointer_router.dart �[38;5;244mE/flutter (12154): #14 PointerRouter.route�[39;49m package:flutter/…/gestures/pointer_router.dart �[38;5;244mE/flutter (12154): #15 GestureBinding.handleEvent�[39;49m package:flutter/…/gestures/binding.dart �[38;5;244mE/flutter (12154): #16 GestureBinding.dispatchEvent�[39;49m package:flutter/…/gestures/binding.dart �[38;5;244mE/flutter (12154): #17 RendererBinding.dispatchEvent�[39;49m package:flutter/…/rendering/binding.dart �[38;5;244mE/flutter (12154): #18 GestureBinding._handlePointerEvent�[39;49m package:flutter/…/gestures/binding.dart �[38;5;244mE/flutter (12154): #19 GestureBinding._flushPointerEventQueue�[39;49m package:flutter/…/gestures/binding.dart �[38;5;244mE/flutter (12154): #20 GestureBinding._handlePointerDataPacket�[39;49m package:flutter/…/gestures/binding.dart �[38;5;244mE/flutter (12154): #21 _rootRunUnary (dart:async/zone.dart:1206:13)�[39;49m �[38;5;244mE/flutter (12154): #22 _CustomZone.runUnary (dart:async/zone.dart:1100:19)�[39;49m �[38;5;244mE/flutter (12154): #23 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)�[39;49m �[38;5;244mE/flutter (12154): #24 _invoke1 (dart:ui/hooks.dart:265:10)�[39;49m �[38;5;244mE/flutter (12154): #25 _dispatchPointerDataPacket (dart:ui/hooks.dart:174:5)�[39;49m E/flutter (12154): D/OpScreenModeManager(12154): setRefreshRate parent io.flutter.embedding.android.FlutterView{1f9461f VFE...... ........ 0,0-1080,2355} parent width 1080 parent height 2355 mRatio 1.2 D/OpScreenModeManager(12154): setRefreshRate view io.flutter.embedding.android.FlutterSurfaceView{595c5be V.E...... ........ 0,0-1080,2355} viewRate 1 width 1080 height 2355 D/OpScreenModeManager(12154): setRefreshRate parent io.flutter.embedding.android.FlutterView{1f9461f VFE...... ........ 0,0-1080,2355} parent width 1080 parent height 2355 mRatio 1.2 D/OpScreenModeManager(12154): setRefreshRate view io.flutter.embedding.android.FlutterSurfaceView{595c5be V.E...... ........ 0,0-1080,2355} viewRate 1 width 1080 height 2355 D/DecorView(12154): onWindowFocusChangedFromViewRoot hasFocus: true, DecorView@480458[MainActivity] D/ViewRootImpl[MainActivity](12154): windowFocusChanged hasFocus=true inTouchMode=true W/DisplayEventDispatcher(12154): dispatcher 0x75fc09fed0 ~ ignoring unknown event type 0x6d746f6e W/DisplayEventDispatcher(12154): dispatcher 0x764c0b6fb0 ~ ignoring unknown event type 0x6d746f6e D/ViewRootImpl[MainActivity](12154): windowFocusChanged hasFocus=false inTouchMode=true
flutter doctor -v
[✓] Flutter (Channel stable, 1.22.6, on macOS 11.2.2 20D80 darwin-x64, locale en-GB) • Flutter version 1.22.6 at /Users/tahatesser/Code/flutter_stable • Framework revision 9b2d32b605 (5 weeks ago), 2021-01-22 14:36:39 -0800 • Engine revision 2f0af37152 • Dart version 2.10.5 [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3) • Android SDK at /Volumes/Extreme/SDK • Platform android-30, build-tools 30.0.3 • ANDROID_HOME = /Volumes/Extreme/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 12.4) • Xcode at /Volumes/Extreme/Xcode.app/Contents/Developer • Xcode 12.4, Build version 12D4e • CocoaPods version 1.10.1 [!] Android Studio (version 4.1) • Android Studio at /Applications/Android Studio.app/Contents ✗ Flutter plugin not installed; this adds Flutter specific functionality. ✗ Dart plugin not installed; this adds Dart specific functionality. • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495) [✓] VS Code (version 1.53.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.20.0 [✓] Connected device (1 available) • IN2011 (mobile) • c9d8ee0c • android-arm64 • Android 11 (API 30) ! Doctor found issues in 1 category.Reacted by Domantas Zavadskis and Danaru- addedfound in release: 1.22Found to occur in 1.22Found to occur in 1.22has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: image_pickerThe Image Picker plugin.The Image Picker plugin.platform-androidAndroid applications specificallyAndroid applications specificallyand removedin triagePresently being triaged by the triage teamPresently being triaged by the triage team
on Mar 2, 2021 - addedP2Important issues not at the top of the work listImportant issues not at the top of the work list
on Mar 4, 2021 16 remaining items
- changed the title
[-][image_picker] Image picker returns null when selecting image from Google Photos with launchMode="singleInstance" [/-][+][image_picker] Image picker returns `null` when selecting image from other apps[/+]on Feb 6, 2023 I've been investigating the issue thoroughly. These are my findings.
The issue occurs when the following conditions are met:
- The activity in the Android manifest runs in
launchMode:singleInstance, - The
Intent.GET_CONTENTintent is used to open the native image picker application, - The user selects a file from Google Photos.
I found that when these steps are taken, the
onActivityResultfunction is called with a result code ofRESULT_CANCELEDinstead ofRESULT_OK.I created a basic native Android app to test whether this also happens on Android-only, as it could potentially be caused by the way Flutter uses the activities. The native app contains the basic activity from the template. On clicking the FAB, I start the image picker activity using the
Intent.ACTION_GET_CONTENTintent.Intent intent = new Intent(Intent.ACTION_GET_CONTENT); startActivityForResult(intent, 1);This all goes well. Then I update the manifest to use
android:launchMode="singleInstance". Now, when opening the file picker and selecting a file from Google Photos, I receive a result codeRESULT_CANCELED.This leads me to believe that this issue is a bug in the Android Image Picker.
Reacted by Lars- The activity in the Android manifest runs in
This leads me to believe that this issue is a bug in the Android Image Picker.
Based on further investigation, it looks like this is expected behavior rather than a bug, as described here. If the calling app forbids other activities it its task, then it can't get results from other activities.
We can document this in the plugin's README to help avoid people being surprised by it.
- changed the title
[-][image_picker] Image picker returns `null` when selecting image from other apps[/-][+][image_picker] Image picker returns `null` when selecting image from other apps when using `singleInstance`[/+]on Apr 13, 2023 stuartmorgan-g commented
on Apr 13, 2023 on Apr 13, 2023 · Hidden as off-topicshow commentMore actions- added a commit that references this issue
on Apr 21, 2023 - addedr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer version
on Apr 24, 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 -vand a minimal reproduction of the issue.- locked as resolved and limited conversation to collaborators
on May 8, 2023 - addedpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.
on Jul 5, 2023
Steps to Reproduce
This code snippet returns null only when selecting image from Google Photos:
And I get this message in log cat: