dart - 如何解决图像选择器崩溃应用程序错误?

标签 dart flutter

我在选择图像时遇到应用程序崩溃。我正在使用 image_picker:0.5.0+7 使用任何 ImageSource 都会使应用程序崩溃。

文件_文件状态;

Future getImage(ImageSource imageSource) async{
  // using your method of getting an image
  final File image = await ImagePicker.pickImage(source: imageSource);

  print("path:: ");
  setState(() {
   // print("path:: "+image.path);
    _fileState = image;
  });

}

Shutting down VM E/AndroidRuntime(16049): FATAL EXCEPTION: main E/AndroidRuntime(16049): Process: com.grain.test_camera, PID: 16049 E/AndroidRuntime(16049): java.lang.RuntimeException: Unable to resume activity {com.grain.test_camera/com.grain.test_camera.MainActivity}: java.lang.RuntimeException: Failure deliver ing result ResultInfo{who=null, request=2342, result=-1, data=Intent { dat=content://com.android.providers.media.documents/document/image:25272 flg=0x1 }} to activity {com.grain.test _camera/com.grain.test_camera.MainActivity}: java.lang.IllegalStateException: Received image from picker that was not requested E/AndroidRuntime(16049): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3506) E/AndroidRuntime(16049): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3546) E/AndroidRuntime(16049): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2795) E/AndroidRuntime(16049): at android.app.ActivityThread.-wrap12(ActivityThread.java) E/AndroidRuntime(16049): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1527) E/AndroidRuntime(16049): at android.os.Handler.dispatchMessage(Handler.java:110) E/AndroidRuntime(16049): at android.os.Looper.loop(Looper.java:203) E/AndroidRuntime(16049): at android.app.ActivityThread.main(ActivityThread.java:6251) E/AndroidRuntime(16049): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime(16049): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063) E/AndroidRuntime(16049): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924) E/AndroidRuntime(16049): Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2342, result=-1, data=Intent { dat=content://com.android.provid ers.media.documents/document/image:25272 flg=0x1 }} to activity {com.grain.test_camera/com.grain.test_camera.MainActivity}: java.lang.IllegalStateException: Received image from picke r that was not requested

我不知道我能做什么请帮帮我

最佳答案

可能与AndroidX兼容性有关。你必须 avoid AndroidXmigrate your project to AndroidX .

在版本 0.5.0 之后有一个突破性的变化

enter image description here

关于dart - 如何解决图像选择器崩溃应用程序错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55335970/

相关文章:

unit-testing - 带有服务器回调的 http 的 Flutter dart 测试

android - 在 android flutter 中使用 gif 图像启动屏幕

Flutter - 当我推送的页面被后退按钮弹出时如何得到通知?

windows - 在 Flutter Windows 应用程序中使用 Firebase 云消息传递

flutter - 如果Dart中的日期为空,如何处理日期?

dart - 函数声明与lambdas

ios - 无法在iPhone上模拟应用程序

android - 每当我尝试运行我的 Flutter 应用程序时,都会执行此任务的 "app:transformClassesWithMultidexlistForDebug"

dart - 如何将属性添加到动态创建的组件

android - 如何在 Flutter 中读取音频扩展并显示在 ListView 中?