1

重现步骤创建一个颤振应用程序。尝试使用 image_picker 插件的最基本功能。

预期成绩:

当您从图库中选择图像时,它应该向您的应用程序返回一些内容。文件或位置。真的什么都有。

实际结果:

没有什么。画廊启动。您选择一个图像。图库消失了,应用程序根本没有返回任何内容。只是留下空。

我的代码

Future getImage() async {
  var image = await ImagePicker.pickImage(source: ImageSource.gallery);
  customImageFile = image.toString();
  print('customImageFile: ' + customImageFile);
}

代码输出

customImageFile: null

插件版本

图像选择器:0.6.5

扑医生

[√] Flutter (Channel stable, v1.12.13+hotfix.5, on Microsoft Windows [Version 10.0.17763.1098], locale en-AU)
• Flutter version 1.12.13+hotfix.5 at c:\flutter
• Framework revision 27321eb (4 months ago), 2019-12-10 18:15:01 -0800
• Engine revision 2994f7e1e6
• Dart version 2.7.0

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at C:\Installations\AndroidSDK
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.2
• ANDROID_HOME = C:\Installations\AndroidSDK
• Java binary at: C:\Installations\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
• All Android licenses accepted.

[√] Android Studio (version 3.5)
• Android Studio at C:\Installations\Android Studio
• Flutter plugin version 40.2.2
• Dart plugin version 191.8593
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)

[√] Connected device (1 available)
• SM G970F • android-arm64 • Android 10 (API 29)

• No issues found!
4

4 回答 4

1
Future getImage() async {
  var image = await ImagePicker().getImage(source: ImageSource.gallery);
  customImageFile = File(image.path);
  print('customImageFile: ' + customImageFile);
}

颤振 2

于 2021-04-15T10:13:00.500 回答
1

您应该将图像变量类型转换为文件:

var image = await ImagePicker().getImage(source: ImageSource.gallery) as File;
于 2021-04-17T12:05:04.727 回答
0

image_picker 在 M1 Mac 上的 IOS 模拟器上返回 null。这是一个仍未解决的问题。使用物理设备。您的代码似乎正确。

于 2021-09-03T16:02:24.967 回答
-2

您需要创建未来的功能。将结果存储在 File bcz 的变量中,它将返回图像路径

Future<File> pickImage(ImageSource source) async{
    File testImage = await ImagePicker.pickImage(source: source);
    setState(() {
      pickedImage = testImage;
    });
  }
于 2020-04-12T06:43:54.113 回答