【问题标题】:Flutter - Unable to access photo gallery in iOS device with flle pickerFlutter - 无法使用文件选择器访问 iOS 设备中的照片库
【发布时间】:2021-04-02 23:37:18
【问题描述】:

请问,有谁能帮我理解为什么在 iOS 中我只能访问 iCloud 文件?我需要用户能够从设备库访问文件(视频和图像)。我不确定这是否是权限问题,但在 info.plist 文件中我有这个:

<key>NSCameraUsageDescription</key>
<string>Allows you to take a picture</string>
<key>NSMicrophoneUsageDescription</key>
<string>Allows you to record a voice</string>
<key>NSAppleMusicUsageDescription</key>
<string>Allows you to choose a music</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Allows you to choose a picture</string>
<key>UIBackgroundModes</key>
<array>
    <string>audio</string>
    <string>fetch</string>
    <string>processing</string>
    <string>remote-notification</string>
</array>

在 Podfile 中,我也有这个:

目标“跑步者”做 使用_frameworks!

在我的代码下面选择视频,最多5个文件,一一选择...

List<Files> _selectedFiles = [];

pickVideos() async {
if (_selectedFiles.length >= 5) {
  Toast.show(t.maximumallowedsizehint, context);
  return;
}
FilePickerResult result = await FilePicker.platform.pickFiles(
  type: FileType.custom,
  // allowCompression: true,
  allowMultiple: true,
  withData: false,
  allowedExtensions: ['mp4'],
);
if (mounted) {
  if (result != null) {
    PlatformFile file = result.files.first;

    print(file.name);
    //print(file.bytes);
    print(file.size);
    print(file.extension);
    print(file.path);
    if (file.size > (1024 * 100)) {
      Toast.show(t.maximumuploadsizehint, context);
      return;
    }

    final filePath = await FlutterAbsolutePath.getAbsolutePath(file.path);
    print("video absolute path " + filePath);
    _selectedFiles.add(new Files(
        link: filePath,
        type: "video",
        filetype: file.extension,
        length: file.size,
        thumbnail: "null"));
    //genThumbnailFile(_selectedFiles.length - 1);
  }
  setState(() {});
}

感谢您的帮助。

【问题讨论】:

  • allowedExtensions: ['mp4', 'jpg'],你试过这个吗?
  • @ShubhamNarkhede 我实际上不想这样做,因为我有另一种方法来选择特定的图像格式......但谢谢。

标签: flutter flutter-dependencies


【解决方案1】:

我已经联系了包所有者 (Miguel Ruivo),他非常友好地回答我提供解决方案。

而不是使用 FileType.custom

FilePickerResult result = await FilePicker.platform.pickFiles(type: FileType.custom);

使用 FileType.media:

FilePickerResult result = await FilePicker.platform.pickFiles(type: FileType.media);

这解决了我的问题!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-18
    • 1970-01-01
    • 2011-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-17
    相关资源
    最近更新 更多