macos_file_picker 0.7.2 copy "macos_file_picker: ^0.7.2" to clipboard
macos_file_picker: ^0.7.2 copied to clipboard

PlatformmacOS

Opens native macOS dialogs to pick files or folders.

macos_file_picker #

pub package

Opens native macOS dialogs to pick files or folders. Features:

  • Pick files, folders or both.
  • Pick a file to save.

Usage #

/// Opens a macOS dialog based on the given arguments.
///
/// [mode]
///   file: pick files.
///   folder: pick folders.
///   fileAndFolder: pick files and folders.
///   saveFile: pick a file saving path.
///
/// [allowsMultiple] when true, allows multiple selection. Default: false.
/// [defaultName] default file name for save dialog.
/// [allowedUtiTypes] allowed UTI types.
/// [allowedFileExtensions] allowed file extensions.
/// [initialDirectory] initial directory. Can be a path or URL.
/// [dialogTitle] title of the dialog window.
///
/// Return value:
///   [null]: dialog closed / cancelled.
///   A list of [MacosFilePickerPath] representing a platform path.
///   When [allowsMultiple] is false, the list should only has one item.
Future<List<MacosFilePickerPath>?> pick(
  MacosFilePickerMode mode, {
  String? defaultName,
  bool? allowsMultiple,
  List<String>? allowedUtiTypes,
  List<String>? allowedFileExtensions,
  String? initialDirectory,
  String? dialogTitle,
});

Example #

final _macosFilePickerPlugin = MacosFilePicker();

Future<void> _openDialog() async {
  // Pick a single file path.
  final result = await _macosFilePickerPlugin.pick(_mode,
      allowsMultiple: _allowsMultiple);
  setState(() {
    _output = result == null ? 'Cancelled' : result.toString();
  });
}