这是导致应用程序崩溃的选择器,它打开图库,但是当我选择图像时,它崩溃。我正在使用Flutter Beta通道,并且pubspec.yaml
image_picker依赖项声明为未指定版本。
我在另一个屏幕上使用了图像选择器,然后效果很好。但是现在它崩溃了,无论是模拟器还是物理设备。
我也不确定为什么该错误包含联系服务插件,我们将不胜感激。
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;
});
}
错误日志
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
答案 0 :(得分:0)
当存在与权限相关的问题时,图像选择器通常会引发此异常。有不同的原因可能会导致这种情况:
您忘记在 AndroidManifest.xml
中插入权限的事实其他插件(例如Permissions_handler,contacts_services等)会产生冲突:
-示例(contacts_services):https://github.com/flutter/flutter/issues/58370
在您的特定情况下,由于您提到了contacts_service插件,因此我认为这两个插件如何处理权限存在一些冲突。