pickFiles static method

Future<List<PlatformFile>> pickFiles({
  1. String? dialogTitle,
  2. String? initialDirectory,
  3. FileType type = FileType.any,
  4. List<String>? allowedExtensions,
  5. dynamic onFileLoading(
    1. FilePickerStatus
    )?,
  6. int compressionQuality = 0,
  7. @Deprecated('use pickFile for single-file selection; this parameter will be removed in a future release') bool allowMultiple = true,
  8. @Deprecated('Use PlatformFile.readAsBytes(); this parameter will be removed in a future release') bool withData = kIsWeb,
  9. @Deprecated('Use PlatformFile.readAsByteStream(); this parameter will be removed in a future release') bool withReadStream = false,
  10. @Deprecated('Use WindowsOptions.lockParentWindow or LinuxOptions.lockParentWindow instead; this parameter will be removed in a future release.') bool lockParentWindow = false,
  11. @Deprecated('Use PlatformFile.readAsByteStream(); this parameter will be removed in a future release') bool readSequential = false,
  12. @Deprecated('Use WebOptions.cancelUploadOnWindowBlur instead; this parameter will be removed in a future release.') bool cancelUploadOnWindowBlur = true,
  13. @Deprecated('Use androidOptions instead.') Object? androidSafOptions,
  14. AndroidOptions androidOptions = const AndroidOptions(),
  15. WindowsOptions windowsOptions = const WindowsOptions(),
  16. LinuxOptions linuxOptions = const LinuxOptions(),
  17. WebOptions webOptions = const WebOptions(),
})

Retrieves the file(s) from the underlying platform.

Opens a native file explorer and lets the user select one or multiple files.

The dialogTitle, if provided, will be used as the title for the picker dialog. The initialDirectory, if provided, will be used as the initial directory path for the picker. The type parameter defines the type of files that can be selected (e.g. FileType.image, FileType.video, etc.). The allowedExtensions parameter can be used to filter by specific file extensions when type is set to FileType.custom. The onFileLoading callback can be used to track picker status changes. The compressionQuality parameter allows compressing picked images/videos on supported platforms (0-100).

The androidOptions, windowsOptions, linuxOptions, and webOptions parameters allow for platform-specific configurations when configuring the file picker.

Returns a list of PlatformFile objects containing the selected files, or an empty list if the user canceled the operation.

Implementation

static Future<List<PlatformFile>> pickFiles({
  String? dialogTitle,
  String? initialDirectory,
  FileType type = FileType.any,
  List<String>? allowedExtensions,
  Function(FilePickerStatus)? onFileLoading,
  int compressionQuality = 0,
  @Deprecated(
    'use pickFile for single-file selection; this parameter will be removed in a future release',
  )
  bool allowMultiple = true,
  @Deprecated(
    'Use PlatformFile.readAsBytes(); this parameter will be removed in a future release',
  )
  bool withData = kIsWeb,
  @Deprecated(
    'Use PlatformFile.readAsByteStream(); this parameter will be removed in a future release',
  )
  bool withReadStream = false,
  @Deprecated(
    'Use WindowsOptions.lockParentWindow or LinuxOptions.lockParentWindow instead; this parameter will be removed in a future release.',
  )
  bool lockParentWindow = false,
  @Deprecated(
    'Use PlatformFile.readAsByteStream(); this parameter will be removed in a future release',
  )
  bool readSequential = false,
  @Deprecated(
    'Use WebOptions.cancelUploadOnWindowBlur instead; this parameter will be removed in a future release.',
  )
  bool cancelUploadOnWindowBlur = true,
  @Deprecated('Use androidOptions instead.') Object? androidSafOptions,
  AndroidOptions androidOptions = const AndroidOptions(),
  WindowsOptions windowsOptions = const WindowsOptions(),
  LinuxOptions linuxOptions = const LinuxOptions(),
  WebOptions webOptions = const WebOptions(),
}) {
  return FilePickerPlatform.instance.pickFiles(
    dialogTitle: dialogTitle,
    initialDirectory: initialDirectory,
    type: type,
    allowedExtensions: allowedExtensions,
    onFileLoading: onFileLoading,
    compressionQuality: compressionQuality,
    androidOptions: _resolveAndroidOptions(androidSafOptions, androidOptions),
    windowsOptions: windowsOptions,
    linuxOptions: linuxOptions,
    webOptions: webOptions,
  );
}