Reputation: 71
This is the picker that is causing the app to crash, It opens gallery but when I choose image, it crashes. I am using the flutter beta channel, and the pubspec.yaml
image_picker dependency is declared with unspecified version.
I used image picker in another screen and it worked fine then. But now it crashes, both the emulator and physical device.
I am also unsure why the error included contact service plugin, any help would be appreciated.
File postPicture;
Future getImage() async {
var tempImage;
if (await Permission.photos.isGranted) {
try {
tempImage = await ImagePicker.pickImage(source: ImageSource.gallery);
} catch (e) {
print(e);
}
}
setState(() {
postPicture = tempImage;
});
}
ERROR LOG
E/AndroidRuntime(27652): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2342, result=-1, data=Intent { dat=content://com.android.providers.media.documents/document/image:25 flg=0x1 }} to activity {com.example.clientApp/com.example.clientApp.MainActivity}: java.lang.NullPointerException: Attempt to invoke interface method 'void io.flutter.plugin.common.MethodChannel$Result.success(java.lang.Object)' on a null object reference
E/AndroidRuntime(27652): at android.app.ActivityThread.deliverResults(ActivityThread.java:4845)
E/AndroidRuntime(27652): at android.app.ActivityThread.handleSendResult(ActivityThread.java:4886)
E/AndroidRuntime(27652): at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
E/AndroidRuntime(27652): at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
E/AndroidRuntime(27652): at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
E/AndroidRuntime(27652): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
E/AndroidRuntime(27652): at android.os.Handler.dispatchMessage(Handler.java:107)
E/AndroidRuntime(27652): at android.os.Looper.loop(Looper.java:214)
E/AndroidRuntime(27652): at android.app.ActivityThread.main(ActivityThread.java:7356)
E/AndroidRuntime(27652): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(27652): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/AndroidRuntime(27652): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
E/AndroidRuntime(27652): Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'void io.flutter.plugin.common.MethodChannel$Result.success(java.lang.Object)' on a null object reference
E/AndroidRuntime(27652): at flutter.plugins.contactsservice.contactsservice.ContactsServicePlugin$BaseContactsServiceDelegate.finishWithResult(ContactsServicePlugin.java:239)
E/AndroidRuntime(27652): at flutter.plugins.contactsservice.contactsservice.ContactsServicePlugin$BaseContactsServiceDelegate.onActivityResult(ContactsServicePlugin.java:255)
E/AndroidRuntime(27652): at io.flutter.embedding.engine.FlutterEnginePluginRegistry$FlutterEngineActivityPluginBinding.onActivityResult(FlutterEnginePluginRegistry.java:691)
E/AndroidRuntime(27652): at io.flutter.embedding.engine.FlutterEnginePluginRegistry.onActivityResult(FlutterEnginePluginRegistry.java:378)
E/AndroidRuntime(27652): at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onActivityResult(FlutterActivityAndFragmentDelegate.java:597)
E/AndroidRuntime(27652): at io.flutter.embedding.android.FlutterActivity.onActivityResult(FlutterActivity.java:582)
E/AndroidRuntime(27652): at android.app.Activity.dispatchActivityResult(Activity.java:8110)
E/AndroidRuntime(27652): at android.app.ActivityThread.deliverResults(ActivityThread.java:4838)
E/AndroidRuntime(27652): ... 11 more
I/Process (27652): Sending signal. PID: 27652 SIG: 9
Upvotes: 1
Views: 1533
Reputation: 2235
Image picker usually throws this exception when there are issues related to the permissions. There are different reasons that may cause this:
The fact that you forgot to insert permissions in the AndroidManifest.xml
Other plugins (like permissions_handler, contacts_services,...) that you inserted are generating conflicts:
-example (contacts_services): https://github.com/flutter/flutter/issues/58370
In your specific case, since you mentioned contacts_service plugin, I think there are some conflicts related to how permissions are handled by these 2 plugins.
Upvotes: 0