dart 图像拾取器问题

kiayqfof  于 2022-12-25  发布在  其他
关注(0)|答案(2)|浏览(162)

我正在尝试使用图像选择器依赖项,但是我遇到了一个小问题。下面是我为图像选择器创建的函数:

pickImage(ImageSource source)async{
    final ImagePicker imagePicker = ImagePicker();

   XFile? file =await imagePicker.pickImage(source: source);
   if(file != null){
     return file.readAsBytes();
   }else{
     print('no image selected');
   }
  }

这是在一个名为_authController的类中创建的,然后我创建了另一个函数,让它专门从库中进行选择

Uint8List? _image;
  final AuthController _authController = AuthController();

  gallarypick()async{
   Uint8List im = await _authController.pickImage(ImageSource.gallery);
   setState(() {
     _image = im;
   });
  }

当我调用这个函数时,它给我这个错误

W/DynamiteModule( 3685): Local module descriptor class for com.google.android.gms.providerinstaller.dynamite not found.
I/DynamiteModule( 3685): Considering local module com.google.android.gms.providerinstaller.dynamite:0 and remote module com.google.android.gms.providerinstaller.dynamite:0
W/ProviderInstaller( 3685): Failed to load providerinstaller module: No acceptable module com.google.android.gms.providerinstaller.dynamite found. Local version is 0 and remote version is 0.
W/ConnectivityManager.CallbackHandler( 3685): callback not found for CALLBACK_AVAILABLE message
D/EGL_emulation( 3685): app_time_stats: avg=163941.78ms min=37.00ms max=654994.19ms count=4
D/EGL_emulation( 3685): app_time_stats: avg=1099.78ms min=894.68ms max=1304.88ms count=2
E/flutter ( 3685): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method pickImage on channel plugins.flutter.io/image_picker)
E/flutter ( 3685): #0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:294:7)
E/flutter ( 3685): <asynchronous suspension>
E/flutter ( 3685): #1      MethodChannelImagePicker.getImageFromSource (package:image_picker_platform_interface/src/method_channel/method_channel_image_picker.dart:209:26)
E/flutter ( 3685): <asynchronous suspension>
E/flutter ( 3685): #2      AuthController.pickImage (package:car_app/controllers/auth_controller.dart:12:17)
E/flutter ( 3685): <asynchronous suspension>
E/flutter ( 3685): #3      _SellerSignUpState.gallarypick (package:car_app/signup%20and%20login/seller%20signup%20and%20login/seller_signup.dart:25:19)
E/flutter ( 3685): <asynchronous suspension>
E/flutter ( 3685):

我不明白出了什么问题。请帮助我

zd287kbt

zd287kbt1#

您可能安装了该软件包并尝试直接执行其代码,image_picker软件包需要从设备进入原生功能,因此需要重新运行应用,而不是热重启/重新加载:

  • 停止运行应用程序
  • 运行flutter clean命令
  • 运行flutter pub get命令

然后再次运行调试应用程序,它应该会工作

vh0rcniy

vh0rcniy2#

请添加必要的android权限像下面在android清单文件,让我知道如果它的作品

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

请参考下面的链接,这是同类的。
https://github.com/flutter/flutter/issues/17545

相关问题