### Pick Files and Directories Source: https://pub.dev/documentation/file_picker/latest/file_picker/FilePicker/pickFileAndDirectoryPaths.html Use this method to display a dialog for selecting multiple files and directories. It is only supported on macOS. The `initialDirectory` parameter can specify the starting path, and `allowedExtensions` can filter file types. ```dart static Future?> pickFileAndDirectoryPaths({ String? initialDirectory, FileType type = FileType.any, List? allowedExtensions, }) { return FilePickerPlatform.instance.pickFileAndDirectoryPaths( initialDirectory: initialDirectory, type: type, allowedExtensions: allowedExtensions, ); } ``` -------------------------------- ### Get XFile from PlatformFile Source: https://pub.dev/documentation/file_picker/latest/file_picker/PlatformFile/xFile.html Retrieves the file as an XFile. Uses XFile.fromData for web platforms and the XFile constructor with a path for other platforms. Ensure bytes, name, and size are available. ```dart XFile get xFile { if (kIsWeb) { return XFile.fromData(bytes!, name: name, length: size); } else { return XFile(path!, name: name, bytes: bytes, length: size); } } ``` -------------------------------- ### Get Names of Picked Files Source: https://pub.dev/documentation/file_picker/latest/file_picker/FilePickerResult/names.html This implementation shows how to retrieve a list of all file names with their extensions from the picked files. ```dart List get names => files.map((file) => file.name).toList(); ``` -------------------------------- ### registerWith static method Source: https://pub.dev/documentation/file_picker/latest/file_picker/FilePickerMacOS/registerWith.html This static method initializes the FilePickerMacOS instance. It should be called during the application's setup phase to ensure the file picker functionality is correctly registered for the macOS platform. ```APIDOC ## registerWith static method ### Description Initializes the FilePickerMacOS instance by assigning it to `FilePickerPlatform.instance`. ### Method Signature `static void registerWith()` ### Implementation Details This method sets the static `instance` of `FilePickerPlatform` to a new `FilePickerMacOS` object. This ensures that subsequent calls to the file picker API on macOS will use the correct platform-specific implementation. ### Usage Call this method once during your application's initialization process, typically in your `main` function or an equivalent setup routine, before any file picking operations are performed. ``` -------------------------------- ### Get paths from picked files Source: https://pub.dev/documentation/file_picker/latest/file_picker/FilePickerResult/paths.html This implementation retrieves the paths of picked files. It checks if the platform is Web and throws an UnsupportedError if it is, as paths are not available on Web. Otherwise, it maps each file to its path. ```dart List get paths => files .map((file) => kIsWeb ? throw UnsupportedError( 'Picking paths is unsupported on Web. Please, use bytes property instead.') : file.path) .toList(); ``` -------------------------------- ### Get Directory Path Implementation (Dart) Source: https://pub.dev/documentation/file_picker/latest/file_picker/FilePicker/getDirectoryPath.html This is the implementation of the getDirectoryPath static method. It delegates the call to the platform instance. Ensure you handle the returned Future which may resolve to null if the user cancels the dialog or the path cannot be resolved. ```dart static Future getDirectoryPath({ String? dialogTitle, bool lockParentWindow = false, String? initialDirectory, }) { return FilePickerPlatform.instance.getDirectoryPath( dialogTitle: dialogTitle, lockParentWindow: lockParentWindow, initialDirectory: initialDirectory, ); } ``` -------------------------------- ### registerWith() Source: https://pub.dev/documentation/file_picker/latest/file_picker/FilePickerLinux/registerWith.html The static registerWith method is used to register the FilePickerLinux implementation with the FilePickerPlatform. This should be called once when the application starts. ```APIDOC ## registerWith() ### Description Registers the FilePickerLinux implementation with the FilePickerPlatform. ### Method Signature `static void registerWith()` ### Implementation Details This method sets `FilePickerPlatform.instance` to a new instance of `FilePickerLinux`. ### Usage Example ```dart void main() { // Register the Linux implementation FilePickerLinux.registerWith(); // Now you can use the file picker // ... } ``` ``` -------------------------------- ### FilePickerLinux() Source: https://pub.dev/documentation/file_picker/latest/file_picker/FilePickerLinux/FilePickerLinux.html Constructs a new FilePickerLinux instance. It initializes the DBus client for session communication and sets up the XDG Desktop Portal file chooser interface. ```APIDOC ## FilePickerLinux() ### Description Initializes a new FilePickerLinux object. This involves setting up a DBus client for the session and creating an instance of the XDG Desktop Portal file chooser. ### Method Constructor ### Parameters None ### Implementation Details ```dart FilePickerLinux() : super() { _client = DBusClient.session(); _xdpChooser = OrgFreedesktopPortalFileChooser(_client, destination, path: DBusObjectPath("/org/freedesktop/portal/desktop")); } ``` ``` -------------------------------- ### FilePickerLinux Constructor Source: https://pub.dev/documentation/file_picker/latest/file_picker/FilePickerLinux-class.html Initializes a new instance of the FilePickerLinux class. ```APIDOC ## FilePickerLinux() ### Description Initializes a new instance of the FilePickerLinux class. ### Method Constructor ``` -------------------------------- ### Get File Extension Source: https://pub.dev/documentation/file_picker/latest/file_picker/PlatformFile/extension.html Retrieves the file extension by splitting the file name and taking the last part. This is useful for identifying the type of file. ```dart String? get extension => name.split('.').last; ``` -------------------------------- ### FilePickerMacOS() Constructor Source: https://pub.dev/documentation/file_picker/latest/file_picker/FilePickerMacOS-class.html Initializes a new instance of the FilePickerMacOS class. ```APIDOC ## FilePickerMacOS() ### Description Initializes a new instance of the FilePickerMacOS class. ### Constructor FilePickerMacOS() ``` -------------------------------- ### Get All Files as XFile List Source: https://pub.dev/documentation/file_picker/latest/file_picker/FilePickerResult/xFiles.html Retrieves a List containing all selected files. This implementation maps internal file representations to XFile objects. ```dart List get xFiles => files.map((file) => file.xFile).toList(); ``` -------------------------------- ### FilePickerWindows constructor Source: https://pub.dev/documentation/file_picker/latest/file_picker/FilePickerWindows/FilePickerWindows.html Initializes a new instance of the FilePickerWindows class. ```APIDOC ## FilePickerWindows() ### Description Initializes a new instance of the FilePickerWindows class. ### Method constructor ### Endpoint N/A ### Parameters This constructor does not take any parameters. ### Request Example ```dart var filePicker = FilePickerWindows(); ``` ### Response #### Success Response (Instance) - **FilePickerWindows** (object) - An instance of the FilePickerWindows class. ``` -------------------------------- ### Implement pickFiles Method Source: https://pub.dev/documentation/file_picker/latest/file_picker/FilePickerWindows/pickFiles.html This is the core implementation of the pickFiles method. It spawns an isolate to handle the file picking process and then processes the results. ```dart @override Future pickFiles({ String? dialogTitle, String? initialDirectory, FileType type = FileType.any, List? allowedExtensions, Function(FilePickerStatus)? onFileLoading, bool allowMultiple = false, bool withData = false, bool withReadStream = false, bool lockParentWindow = false, bool readSequential = false, int compressionQuality = 0, bool cancelUploadOnWindowBlur = true, }) async { final port = ReceivePort(); await Isolate.spawn( _callPickFiles, _OpenSaveFileArgs( port: port.sendPort, dialogTitle: dialogTitle, initialDirectory: initialDirectory, type: type, allowedExtensions: allowedExtensions, allowMultiple: allowMultiple, lockParentWindow: lockParentWindow, ), ); final fileNames = (await port.first) as List?; FilePickerResult? returnValue; if (fileNames != null) { final filePaths = fileNames; final platformFiles = await FilePickerUtils.filePathsToPlatformFiles( filePaths, withReadStream, withData, ); returnValue = FilePickerResult(platformFiles); } return returnValue; } ``` -------------------------------- ### Get the number of picked files Source: https://pub.dev/documentation/file_picker/latest/file_picker/FilePickerResult/count.html Use the `count` getter to retrieve the total number of files selected. This property is a direct getter for the length of the internal files list. ```dart int get count => files.length; ``` -------------------------------- ### pickFileAndDirectoryPaths method Source: https://pub.dev/documentation/file_picker/latest/file_picker/FilePickerWindows/pickFileAndDirectoryPaths.html Displays a dialog that allows the user to select both files and directories simultaneously, returning their absolute paths. ```APIDOC ## pickFileAndDirectoryPaths ### Description Displays a dialog that allows the user to select both files and directories simultaneously, returning their absolute paths. ### Method Signature Future?> pickFileAndDirectoryPaths({ String? initialDirectory, FileType type = FileType.any, List? allowedExtensions, }) ### Parameters #### Parameters - **initialDirectory** (String?) - Optional - The directory to open the file picker in. - **type** (FileType) - Optional - Defaults to FileType.any. Specifies the type of files that can be selected. - **allowedExtensions** (List?) - Optional - A list of file extensions that are allowed to be selected. ### Implementation Notes This method is intended to be implemented by the platform-specific FilePickerWindows class. The provided code shows an unimplemented stub. ``` -------------------------------- ### Pick Multiple Files with Extension Filter Source: https://pub.dev/documentation/file_picker/latest/index.html Configure the file picker to accept only specific file extensions, such as 'jpg', 'pdf', or 'doc'. This helps in guiding user selection. ```dart FilePickerResult? result = await FilePicker.pickFiles( allowMultiple: true, type: FileType.custom, allowedExtensions: ['jpg', 'pdf', 'doc'], ); ``` -------------------------------- ### pickFileAndDirectoryPaths Method Source: https://pub.dev/documentation/file_picker/latest/file_picker/FilePickerLinux/pickFileAndDirectoryPaths.html Displays a dialog that allows the user to select both files and directories simultaneously, returning their absolute paths. ```APIDOC ## pickFileAndDirectoryPaths Method ### Description Displays a dialog that allows the user to select both files and directories simultaneously, returning their absolute paths. ### Signature ```dart Future?> pickFileAndDirectoryPaths({ String? initialDirectory, FileType type = FileType.any, List? allowedExtensions, }) ``` ### Parameters #### Optional Parameters - **initialDirectory** (String?) - The directory to open the file picker in. Defaults to the user's home directory. - **type** (FileType) - The type of files to pick. Defaults to `FileType.any`. - **allowedExtensions** (List?) - A list of file extensions that are allowed to be picked. If null, all extensions are allowed. ``` -------------------------------- ### pickFileAndDirectoryPaths Method Source: https://pub.dev/documentation/file_picker/latest/file_picker/FilePickerMacOS/pickFileAndDirectoryPaths.html Displays a dialog that allows the user to select both files and directories simultaneously, returning their absolute paths. ```APIDOC ## pickFileAndDirectoryPaths Method ### Description Displays a dialog that allows the user to select both files and directories simultaneously, returning their absolute paths. ### Method Signature Future?> pickFileAndDirectoryPaths({ String? initialDirectory, FileType type = FileType.any, List? allowedExtensions, }) ### Parameters #### Optional Parameters - **initialDirectory** (String?) - The directory to open the file picker in. - **type** (FileType) - The type of files to allow. Defaults to FileType.any. - **allowedExtensions** (List?) - A list of file extensions to allow. ``` -------------------------------- ### pickFiles() Source: https://pub.dev/documentation/file_picker/latest/file_picker/FilePickerWindows-class.html Retrieves the file(s) from the underlying platform. ```APIDOC ## pickFiles({String? dialogTitle, String? initialDirectory, FileType type = FileType.any, List? allowedExtensions, dynamic onFileLoading(FilePickerStatus)?, bool allowMultiple = false, bool withData = false, bool withReadStream = false, bool lockParentWindow = false, bool readSequential = false, int compressionQuality = 0, bool cancelUploadOnWindowBlur = true}) ### Description Retrieves the file(s) from the underlying platform. ### Parameters - **dialogTitle** (String?) - Optional - The title of the dialog window. - **initialDirectory** (String?) - Optional - The directory that the dialog will open in. - **type** (FileType) - Optional - Defaults to `FileType.any`. The type of files to pick. - **allowedExtensions** (List?) - Optional - A list of allowed file extensions. - **onFileLoading** (dynamic) - Optional - A callback function for when a file is loading. - **allowMultiple** (bool) - Optional - Defaults to `false`. If true, allows multiple files to be selected. - **withData** (bool) - Optional - Defaults to `false`. If true, includes file data. - **withReadStream** (bool) - Optional - Defaults to `false`. If true, includes a read stream for files. - **lockParentWindow** (bool) - Optional - Defaults to `false`. If true, the parent window will be locked. - **readSequential** (bool) - Optional - Defaults to `false`. If true, reads files sequentially. - **compressionQuality** (int) - Optional - Defaults to `0`. The compression quality for images. - **cancelUploadOnWindowBlur** (bool) - Optional - Defaults to `true`. If true, cancels upload on window blur. ``` -------------------------------- ### FilePickerLinux Constructor Implementation Source: https://pub.dev/documentation/file_picker/latest/file_picker/FilePickerLinux/FilePickerLinux.html Initializes the DBus client and the XDG Desktop Portal file chooser. This is the default constructor for FilePickerLinux. ```dart FilePickerLinux() : super() { _client = DBusClient.session(); _xdpChooser = OrgFreedesktopPortalFileChooser(_client, destination, path: DBusObjectPath("/org/freedesktop/portal/desktop")); } ``` -------------------------------- ### pickFiles Method Source: https://pub.dev/documentation/file_picker/latest/file_picker/FilePickerMacOS/pickFiles.html Retrieves the file(s) from the underlying platform. This method allows for various configurations such as dialog title, initial directory, file types, compression quality, and whether to allow multiple file selections. ```APIDOC ## pickFiles Method ### Description Retrieves the file(s) from the underlying platform. This method allows for various configurations such as dialog title, initial directory, file types, compression quality, and whether to allow multiple file selections. ### Method Signature Future pickFiles({ String? dialogTitle, String? initialDirectory, FileType type = FileType.any, List? allowedExtensions, Function(FilePickerStatus)? onFileLoading, int compressionQuality = 0, bool allowMultiple = false, bool withData = false, bool withReadStream = false, bool lockParentWindow = false, bool readSequential = false, bool cancelUploadOnWindowBlur = true, }) ### Parameters #### Optional Parameters - **dialogTitle** (String?) - The title of the file picker dialog. - **initialDirectory** (String?) - The directory that the file picker dialog will open to. - **type** (FileType) - The type of files to pick. Defaults to `FileType.any`. - **allowedExtensions** (List?) - A list of file extensions that are allowed to be picked. - **onFileLoading** (Function(FilePickerStatus)?) - A callback function that is called when a file is being loaded. - **compressionQuality** (int) - The compression quality to use for images. Defaults to 0 (no compression). - **allowMultiple** (bool) - Whether to allow multiple file selections. Defaults to false. - **withData** (bool) - Whether to include the file data in the result. Defaults to false. - **withReadStream** (bool) - Whether to include a read stream for the file in the result. Defaults to false. - **lockParentWindow** (bool) - Whether to lock the parent window while the file picker is open. Defaults to false. - **readSequential** (bool) - Whether to read files sequentially. Defaults to false. - **cancelUploadOnWindowBlur** (bool) - Whether to cancel the upload if the window loses focus. Defaults to true. ### Return Value - **Future** - A Future that resolves to a FilePickerResult object containing the selected files, or null if the user cancels the operation. ``` -------------------------------- ### pickFiles static method Source: https://pub.dev/documentation/file_picker/latest/file_picker/FilePicker/pickFiles.html Retrieves the file(s) from the underlying platform. Supports various options for dialog title, initial directory, file types, extensions, loading status, compression, multiple selection, data retrieval, read stream, window locking, sequential reading, and upload cancellation on window blur. ```APIDOC ## pickFiles static method ### Description Retrieves the file(s) from the underlying platform. Default `type` set to FileType.any with `allowMultiple` set to `false`. Optionally, `allowedExtensions` might be provided (e.g. `[pdf, svg, jpg]`.). If `withData` is set, picked files will have its byte data immediately available on memory as `Uint8List` which can be useful if you are picking it for server upload or similar. However, have in mind that enabling this on IO (iOS & Android) may result in out of memory issues if you allow multiple picks or pick huge files. Use `withReadStream` instead. Defaults to `true` on web, `false` otherwise. Not supported on macOS. If `withReadStream` is set, picked files will have its byte data available as a Stream> which can be useful for uploading and processing large files. Defaults to `false`. Not supported on macOS. If you want to track picking status, for example, because some files may take some time to be cached (particularly those picked from cloud providers), you may want to set `onFileLoading` handler that will give you the current status of picking. Not supported on macOS. If `lockParentWindow` is set, the child window (file picker window) will stay in front of the Flutter window until it is closed (like a modal window). This parameter works only on Windows desktop. On macOS the parent window will be locked and this parameter is ignored. `dialogTitle` can be optionally set on desktop platforms to set the modal window title. Not supported on macOS. It will be ignored on other platforms. `initialDirectory` can be optionally set to an absolute path to specify where the dialog should open. Only supported on Linux, macOS, and Windows. On macOS the home directory shortcut (~/) is not necessary and passing it will be ignored. On macOS if the `initialDirectory` is invalid the user directory or previously valid directory will be used. `readSequential` can be optionally set on web to keep the import file order during import. Not supported on macOS. `cancelUploadOnWindowBlur` prevents upload cancellation when window focus is lost. Only supported on web. The result is wrapped in a FilePickerResult which contains helper getters with useful information regarding the picked List. For more information, check the API documentation. Note: This requires the User Selected File Read entitlement on macOS. Returns `null` if aborted. ### Method Signature ```dart static Future pickFiles({ String? dialogTitle, String? initialDirectory, FileType type = FileType.any, List? allowedExtensions, Function(FilePickerStatus)? onFileLoading, int compressionQuality = 0, bool allowMultiple = false, bool withData = false, bool withReadStream = false, bool lockParentWindow = false, bool readSequential = false, bool cancelUploadOnWindowBlur = true, }) ``` ### Parameters * **dialogTitle** (String?) - Optional - The title of the modal window for the file picker dialog. Only supported on desktop platforms (Windows, Linux). Ignored on macOS and other platforms. * **initialDirectory** (String?) - Optional - An absolute path to specify the directory where the file picker dialog should open. Supported on Linux, macOS, and Windows. On macOS, if the path is invalid, the user's home directory or the previously used directory will be used. * **type** (FileType) - Optional - The type of files to pick. Defaults to `FileType.any`. * **allowedExtensions** (List?) - Optional - A list of file extensions that are allowed to be picked (e.g., `['pdf', 'svg', 'jpg']`). * **onFileLoading** (Function(FilePickerStatus)?) - Optional - A callback function that is invoked to track the status of file picking. Not supported on macOS. * **compressionQuality** (int) - Optional - The compression quality to use for picked images. Defaults to 0 (no compression). * **allowMultiple** (bool) - Optional - Whether to allow picking multiple files. Defaults to `false`. * **withData** (bool) - Optional - If true, picked files will have their byte data available as `Uint8List` in memory. Defaults to `true` on web, `false` otherwise. Not supported on macOS. Be cautious on IO platforms (iOS, Android) with large files or multiple selections to avoid memory issues. * **withReadStream** (bool) - Optional - If true, picked files will have their byte data available as a `Stream>`. Defaults to `false`. Not supported on macOS. Useful for uploading and processing large files. * **lockParentWindow** (bool) - Optional - If true, the file picker window will remain in front of the parent Flutter window until closed (modal behavior). Only supported on Windows desktop. Ignored on macOS. * **readSequential** (bool) - Optional - If true, the import order of files will be maintained during import. Only supported on web. Not supported on macOS. * **cancelUploadOnWindowBlur** (bool) - Optional - If true, prevents upload cancellation when the window loses focus. Only supported on web. ### Returns A `Future` which resolves to a `FilePickerResult` object containing information about the picked files, or `null` if the operation was aborted. ``` -------------------------------- ### Linux File Picker Implementation Source: https://pub.dev/documentation/file_picker/latest/file_picker/FilePickerLinux/pickFiles.html This code implements the pickFiles method for Linux, utilizing the xdg-desktop-portal for file selection. It handles various options like file types, multiple selections, and initial directories. ```dart @override Future pickFiles({ String? dialogTitle, String? initialDirectory, FileType type = FileType.any, List? allowedExtensions, Function(FilePickerStatus)? onFileLoading, bool allowMultiple = false, bool withData = false, bool withReadStream = false, bool lockParentWindow = false, bool readSequential = false, int compressionQuality = 0, bool cancelUploadOnWindowBlur = true, }) async { final filter = Filter(type, allowedExtensions); Map xdpOption = { 'handle_token': DBusString('flutter_picker'), 'multiple': DBusBoolean(allowMultiple), 'modal': DBusBoolean(lockParentWindow), 'filters': filter.toDBusArray(), }; if (initialDirectory != null) { final Uint8List tmp = _encodeDirectory(initialDirectory); DBusArray directory = DBusArray.byte(tmp); xdpOption["current_folder"] = directory; } final replyPath = await _xdpChooser.callOpenFile( "", dialogTitle ?? "flutter picker", xdpOption); List uriPaths = []; final request = OrgFreedesktopPortalRequest(_client, destination, path: replyPath); await for (var response in request.response) { final status = response.response; // Maybe cancelled if (status != 0) { return null; } final result = response.results; uriPaths = result["uris"] ?.asArray() .map((data) => Uri.parse(data.asString())) .toList() ?? []; break; } final filePaths = uriPaths.map((uri) => uri.toFilePath()).toList(); final List platformFiles = await FilePickerUtils.filePathsToPlatformFiles( filePaths, withReadStream, withData, ); return FilePickerResult(platformFiles); } ``` -------------------------------- ### FilePickerMacOS Constructor Source: https://pub.dev/documentation/file_picker/latest/file_picker/FilePickerMacOS/FilePickerMacOS.html Initializes a new instance of the FilePickerMacOS class. ```APIDOC ## FilePickerMacOS() ### Description Constructs a new FilePickerMacOS object. ### Method constructor ### Endpoint N/A (Class Constructor) ### Parameters None ### Request Example ```dart var filePicker = FilePickerMacOS(); ``` ### Response #### Success Response Initializes a FilePickerMacOS object. #### Response Example N/A (Constructor) ``` -------------------------------- ### PlatformFile Methods Source: https://pub.dev/documentation/file_picker/latest/file_picker/PlatformFile-class.html Methods available on a PlatformFile instance. ```APIDOC ## Methods ### noSuchMethod `dynamic noSuchMethod(Invocation invocation)` Invoked when a nonexistent method or property is accessed. ### toString `String toString()` A string representation of this object. ``` -------------------------------- ### Retrieve Files as XFiles Source: https://pub.dev/documentation/file_picker/latest/index.html Demonstrates how to retrieve picked files either as a list of XFile objects or individually from the FilePickerResult. ```dart FilePickerResult? result = await FilePicker.pickFiles(); if (result != null) { // All files List xFiles = result.xFiles; // Individually XFile xFile = result.files.first.xFile; } else { // User canceled the picker } ``` -------------------------------- ### PlatformFile Constructor Implementation Source: https://pub.dev/documentation/file_picker/latest/file_picker/PlatformFile/PlatformFile.html The actual implementation of the PlatformFile constructor, initializing its properties. ```dart PlatformFile({ this.path, required this.name, required this.size, this.bytes, this.readStream, this.identifier, }); ``` -------------------------------- ### Register FilePickerLinux Instance Source: https://pub.dev/documentation/file_picker/latest/file_picker/FilePickerLinux/registerWith.html Call this static method to set the FilePickerLinux as the instance for the FilePickerPlatform. This should be done during application initialization. ```dart static void registerWith() { FilePickerPlatform.instance = FilePickerLinux(); } ``` -------------------------------- ### PlatformFile Constructors Source: https://pub.dev/documentation/file_picker/latest/file_picker/PlatformFile-class.html Constructors for creating PlatformFile instances. ```APIDOC ## Constructors ### PlatformFile ```dart PlatformFile({ String? path, required String name, required int size, Uint8List? bytes, Stream>? readStream, String? identifier, }) ``` ### PlatformFile.fromMap ```dart PlatformFile.fromMap(Map data, {Stream>? readStream}) ``` ``` -------------------------------- ### pickFiles Method Source: https://pub.dev/documentation/file_picker/latest/file_picker/FilePickerWindows/pickFiles.html Retrieves the file(s) from the underlying platform. This method opens a file picker dialog and returns the selected files. ```APIDOC ## pickFiles Method ### Description Retrieves the file(s) from the underlying platform. This method opens a file picker dialog and returns the selected files. ### Method Signature Future pickFiles({ String? dialogTitle, String? initialDirectory, FileType type = FileType.any, List? allowedExtensions, Function(FilePickerStatus)? onFileLoading, bool allowMultiple = false, bool withData = false, bool withReadStream = false, bool lockParentWindow = false, bool readSequential = false, int compressionQuality = 0, bool cancelUploadOnWindowBlur = true, }) ### Parameters - **dialogTitle** (String?) - Optional - The title displayed in the file picker dialog. - **initialDirectory** (String?) - Optional - The directory that the file picker dialog will open in. - **type** (FileType) - Optional - Defaults to FileType.any. Specifies the type of files that can be selected (e.g., any, audio, image, video, custom). - **allowedExtensions** (List?) - Optional - A list of file extensions that are allowed to be selected. This is used when `type` is set to FileType.custom. - **onFileLoading** (Function(FilePickerStatus)?) - Optional - A callback function that is invoked when the file loading status changes. - **allowMultiple** (bool) - Optional - Defaults to false. If true, allows the user to select multiple files. - **withData** (bool) - Optional - Defaults to false. If true, the file data will be included in the result. - **withReadStream** (bool) - Optional - Defaults to false. If true, a read stream for the file will be included in the result. - **lockParentWindow** (bool) - Optional - Defaults to false. If true, the parent window will be locked until the file picker dialog is closed. - **readSequential** (bool) - Optional - Defaults to false. If true, files will be read sequentially. - **compressionQuality** (int) - Optional - Defaults to 0. Specifies the compression quality for images (0-100). - **cancelUploadOnWindowBlur** (bool) - Optional - Defaults to true. If true, the upload will be canceled if the window loses focus. ### Returns - **Future** - A Future that resolves to a FilePickerResult object containing the selected files, or null if the dialog was canceled. ``` -------------------------------- ### getDirectoryPath Method Implementation Source: https://pub.dev/documentation/file_picker/latest/file_picker/FilePickerLinux/getDirectoryPath.html Implements the directory selection functionality for Linux using DBus. It configures portal options, calls the openFile method, processes the response, and converts the resulting URIs to platform file paths. ```dart @override Future getDirectoryPath({ String? dialogTitle, bool lockParentWindow = false, String? initialDirectory, }) async { Map xdpOption = { 'handle_token': DBusString('flutter_picker'), 'directory': DBusBoolean(true), 'modal': DBusBoolean(lockParentWindow), }; if (initialDirectory != null) { final Uint8List tmp = _encodeDirectory(initialDirectory); DBusArray directory = DBusArray.byte(tmp); xdpOption["current_folder"] = directory; } final replyPath = await _xdpChooser.callOpenFile( "", dialogTitle ?? "flutter picker", xdpOption); List uriPaths = []; final request = OrgFreedesktopPortalRequest(_client, destination, path: replyPath); await for (var response in request.response) { final status = response.response; // Maybe cancelled if (status != 0) { return null; } final result = response.results; uriPaths = result["uris"] ?.asArray() .map((data) => Uri.parse(data.asString())) .toList() ?? []; break; } final filePaths = uriPaths.map((uri) => uri.toFilePath()).toList(); final List platformFiles = await FilePickerUtils.filePathsToPlatformFiles( filePaths, false, false, ); return platformFiles.firstOrNull?.path; } ``` -------------------------------- ### pickFileAndDirectoryPaths() Source: https://pub.dev/documentation/file_picker/latest/file_picker/FilePickerWindows-class.html Displays a dialog that allows the user to select both files and directories simultaneously, returning their absolute paths. ```APIDOC ## pickFileAndDirectoryPaths({String? initialDirectory, FileType type = FileType.any, List? allowedExtensions}) ### Description Displays a dialog that allows the user to select both files and directories simultaneously, returning their absolute paths. ### Parameters - **initialDirectory** (String?) - Optional - The directory that the dialog will open in. - **type** (FileType) - Optional - Defaults to `FileType.any`. The type of files to pick. - **allowedExtensions** (List?) - Optional - A list of allowed file extensions. ``` -------------------------------- ### pickFiles Source: https://pub.dev/documentation/file_picker/latest/file_picker/FilePickerLinux-class.html Retrieves the file(s) from the underlying platform. ```APIDOC ## pickFiles({String? dialogTitle, String? initialDirectory, FileType type = FileType.any, List? allowedExtensions, dynamic onFileLoading(FilePickerStatus)?, bool allowMultiple = false, bool withData = false, bool withReadStream = false, bool lockParentWindow = false, bool readSequential = false, int compressionQuality = 0, bool cancelUploadOnWindowBlur = true}) ### Description Retrieves the file(s) from the underlying platform. ### Method pickFiles ### Parameters #### Query Parameters - **dialogTitle** (String?) - Optional - The title of the dialog window. - **initialDirectory** (String?) - Optional - The directory to open the dialog in initially. - **type** (FileType) - Optional - The type of files to pick. Defaults to FileType.any. - **allowedExtensions** (List?) - Optional - A list of allowed file extensions. - **onFileLoading** (dynamic) - Optional - A callback function for when files are loading. - **allowMultiple** (bool) - Optional - Whether to allow multiple file selections. Defaults to false. - **withData** (bool) - Optional - Whether to include file data. Defaults to false. - **withReadStream** (bool) - Optional - Whether to include file read streams. Defaults to false. - **lockParentWindow** (bool) - Optional - Whether to lock the parent window during dialog display. Defaults to false. - **readSequential** (bool) - Optional - Whether to read files sequentially. Defaults to false. - **compressionQuality** (int) - Optional - The compression quality for images. Defaults to 0. - **cancelUploadOnWindowBlur** (bool) - Optional - Whether to cancel upload on window blur. Defaults to true. ``` -------------------------------- ### pickFiles Source: https://pub.dev/documentation/file_picker/latest/file_picker/FilePickerMacOS-class.html Retrieves the file(s) from the underlying platform. ```APIDOC ## pickFiles ### Description Retrieves the file(s) from the underlying platform. ### Method Future pickFiles({String? dialogTitle, String? initialDirectory, FileType type = FileType.any, List? allowedExtensions, dynamic onFileLoading(FilePickerStatus)?, int compressionQuality = 0, bool allowMultiple = false, bool withData = false, bool withReadStream = false, bool lockParentWindow = false, bool readSequential = false, bool cancelUploadOnWindowBlur = true}) ### Parameters #### Query Parameters - **dialogTitle** (String?) - Optional - The title of the file picker dialog. - **initialDirectory** (String?) - Optional - The initial directory to display in the dialog. - **type** (FileType) - Optional - The type of files to allow selection (e.g., FileType.any, FileType.audio, FileType.image). - **allowedExtensions** (List?) - Optional - A list of allowed file extensions. - **onFileLoading** (dynamic Function(FilePickerStatus)?) - Optional - A callback function to be invoked when a file is loading. - **compressionQuality** (int) - Optional - The compression quality for images (0-100). - **allowMultiple** (bool) - Optional - Whether to allow multiple file selection. - **withData** (bool) - Optional - Whether to include file data in the result. - **withReadStream** (bool) - Optional - Whether to include a read stream for files. - **lockParentWindow** (bool) - Optional - Whether to lock the parent window during the dialog. - **readSequential** (bool) - Optional - Whether to read files sequentially. - **cancelUploadOnWindowBlur** (bool) - Optional - Whether to cancel upload on window blur. ``` -------------------------------- ### FilePickerWindows() Source: https://pub.dev/documentation/file_picker/latest/file_picker/FilePickerWindows-class.html Constructor for the FilePickerWindows class. ```APIDOC ## FilePickerWindows() ### Description Constructor for the FilePickerWindows class. ``` -------------------------------- ### Load File Details Source: https://pub.dev/documentation/file_picker/latest/index.html After picking files, this snippet shows how to access details of the selected file, including its name, bytes, size, extension, and path. ```dart FilePickerResult? result = await FilePicker.pickFiles(); if (result != null) { PlatformFile file = result.files.first; print(file.name); print(file.bytes); print(file.size); print(file.extension); print(file.path); } else { // User canceled the picker } ``` -------------------------------- ### Pick Directory Path Source: https://pub.dev/documentation/file_picker/latest/index.html Allows the user to select a directory instead of a file. Returns null if the user cancels the dialog. ```dart String? selectedDirectory = await FilePicker.getDirectoryPath(); if (selectedDirectory == null) { // User canceled the picker } ``` -------------------------------- ### Implement pickFiles Method in FilePickerMacOS Source: https://pub.dev/documentation/file_picker/latest/file_picker/FilePickerMacOS/pickFiles.html This is the implementation of the pickFiles method for the macOS platform. It handles file type filtering, multiple file selection, and invokes the platform's file picker. Ensure that the method channel and utility functions are correctly set up. ```dart @override Future pickFiles({ String? dialogTitle, String? initialDirectory, FileType type = FileType.any, List? allowedExtensions, Function(FilePickerStatus)? onFileLoading, int compressionQuality = 0, bool allowMultiple = false, bool withData = false, bool withReadStream = false, bool lockParentWindow = false, bool readSequential = false, bool cancelUploadOnWindowBlur = true, }) async { final fileFilter = fileTypeToFileFilter( type, allowedExtensions, ); final filePaths = await methodChannel.invokeListMethod( 'pickFiles', { 'allowedExtensions': fileFilter, 'initialDirectory': escapeInitialDirectory(initialDirectory), 'allowMultiple': allowMultiple, }, ); if (filePaths == null) { return null; } final List platformFiles = await FilePickerUtils.filePathsToPlatformFiles( filePaths, withReadStream, withData, ); return FilePickerResult(platformFiles); } ``` -------------------------------- ### pickFileAndDirectoryPaths Source: https://pub.dev/documentation/file_picker/latest/file_picker/FilePicker-class.html Displays a dialog that allows the user to select both files and directories simultaneously, returning their absolute paths. Supports specifying an initial directory, file type, and allowed extensions. ```APIDOC ## pickFileAndDirectoryPaths({String? initialDirectory, FileType type = FileType.any, List? allowedExtensions}) ### Description Displays a dialog that allows the user to select both files and directories simultaneously, returning their absolute paths. ### Parameters #### Query Parameters - **initialDirectory** (String?) - Optional - The directory to open the dialog in initially. - **type** (FileType) - Optional - The type of files to pick. Defaults to FileType.any. - **allowedExtensions** (List?) - Optional - A list of file extensions that are allowed to be picked. ### Returns - Future?>: A future that completes with a list of absolute paths for the selected files and directories, or null if the user cancels the selection. ``` -------------------------------- ### PlatformFile Constructor Signature Source: https://pub.dev/documentation/file_picker/latest/file_picker/PlatformFile/PlatformFile.html Defines the parameters for creating a PlatformFile instance. Path is optional, while name, size are required. Bytes and readStream can be provided for file content. ```dart PlatformFile({ 1. String? path, 2. required String name, 3. required int size, 4. Uint8List? bytes, 5. Stream>? readStream, 6. String? identifier, }) ``` -------------------------------- ### pickFileAndDirectoryPaths Source: https://pub.dev/documentation/file_picker/latest/file_picker/FilePickerLinux-class.html Displays a dialog that allows the user to select both files and directories simultaneously, returning their absolute paths. ```APIDOC ## pickFileAndDirectoryPaths({String? initialDirectory, FileType type = FileType.any, List? allowedExtensions}) ### Description Displays a dialog that allows the user to select both files and directories simultaneously, returning their absolute paths. ### Method pickFileAndDirectoryPaths ### Parameters #### Query Parameters - **initialDirectory** (String?) - Optional - The directory to open the dialog in initially. - **type** (FileType) - Optional - The type of files to pick. Defaults to FileType.any. - **allowedExtensions** (List?) - Optional - A list of allowed file extensions. ``` -------------------------------- ### pickFileAndDirectoryPaths Source: https://pub.dev/documentation/file_picker/latest/file_picker/FilePickerMacOS-class.html Displays a dialog that allows the user to select both files and directories simultaneously, returning their absolute paths. ```APIDOC ## pickFileAndDirectoryPaths ### Description Displays a dialog that allows the user to select both files and directories simultaneously, returning their absolute paths. ### Method Future?> pickFileAndDirectoryPaths({String? initialDirectory, FileType type = FileType.any, List? allowedExtensions}) ### Parameters #### Query Parameters - **initialDirectory** (String?) - Optional - The initial directory to display in the dialog. - **type** (FileType) - Optional - The type of files to allow selection (e.g., FileType.any, FileType.audio, FileType.image). - **allowedExtensions** (List?) - Optional - A list of allowed file extensions. ``` -------------------------------- ### Pick Files Implementation Source: https://pub.dev/documentation/file_picker/latest/file_picker/FilePicker/pickFiles.html The implementation of the pickFiles static method, which delegates the actual file picking operation to the FilePickerPlatform instance. This method provides a unified interface across different platforms. ```dart { return FilePickerPlatform.instance.pickFiles( dialogTitle: dialogTitle, initialDirectory: initialDirectory, type: type, allowedExtensions: allowedExtensions, onFileLoading: onFileLoading, compressionQuality: compressionQuality, allowMultiple: allowMultiple, withData: withData, withReadStream: withReadStream, lockParentWindow: lockParentWindow, readSequential: readSequential, cancelUploadOnWindowBlur: cancelUploadOnWindowBlur, ); } ``` -------------------------------- ### PlatformFile Constructor Source: https://pub.dev/documentation/file_picker/latest/file_picker/PlatformFile/PlatformFile.html Constructs a PlatformFile object with the specified properties. ```APIDOC ## PlatformFile constructor PlatformFile({ 1. String? path, 2. required String name, 3. required int size, 4. Uint8List? bytes, 5. Stream>? readStream, 6. String? identifier, }) ### Parameters #### Path Parameters - **path** (String?) - Optional - The file path. - **name** (String) - Required - The name of the file. - **size** (int) - Required - The size of the file in bytes. - **bytes** (Uint8List?) - Optional - The file content as a byte list. - **readStream** (Stream>?) - Optional - A stream to read the file content. - **identifier** (String?) - Optional - A unique identifier for the file. ``` -------------------------------- ### Register FilePickerWindows Implementation Source: https://pub.dev/documentation/file_picker/latest/file_picker/FilePickerWindows/registerWith.html Call this static method to set FilePickerWindows as the instance for FilePickerPlatform. This is typically done during application initialization. ```dart static void registerWith() { FilePickerPlatform.instance = FilePickerWindows(); } ``` -------------------------------- ### Implement pickFileAndDirectoryPaths in FilePickerMacOS Source: https://pub.dev/documentation/file_picker/latest/file_picker/FilePickerMacOS/pickFileAndDirectoryPaths.html This method displays a dialog for selecting files and directories. It takes an optional initial directory and file type filters. Returns a list of absolute paths for the selected items. ```dart @override Future?> pickFileAndDirectoryPaths({ String? initialDirectory, FileType type = FileType.any, List? allowedExtensions, }) async { final fileFilter = fileTypeToFileFilter( type, allowedExtensions, ); final filePaths = await methodChannel.invokeListMethod( 'pickFileAndDirectoryPaths', { 'allowedExtensions': fileFilter, 'initialDirectory': escapeInitialDirectory(initialDirectory), }, ); return filePaths; } ``` -------------------------------- ### pickFiles Source: https://pub.dev/documentation/file_picker/latest/file_picker/FilePicker-class.html Retrieves the file(s) from the underlying platform. This method supports various options for customization, including multiple file selection, data retrieval, read streams, and more. ```APIDOC ## pickFiles({String? dialogTitle, String? initialDirectory, FileType type = FileType.any, List? allowedExtensions, dynamic onFileLoading(FilePickerStatus)?, int compressionQuality = 0, bool allowMultiple = false, bool withData = false, bool withReadStream = false, bool lockParentWindow = false, bool readSequential = false, bool cancelUploadOnWindowBlur = true}) ### Description Retrieves the file(s) from the underlying platform. This method supports various options for customization, including multiple file selection, data retrieval, read streams, and more. ### Parameters #### Query Parameters - **dialogTitle** (String?) - Optional - The title for the file picking dialog. - **initialDirectory** (String?) - Optional - The directory to open the dialog in initially. - **type** (FileType) - Optional - The type of files to pick. Defaults to FileType.any. - **allowedExtensions** (List?) - Optional - A list of file extensions that are allowed to be picked. - **onFileLoading** (dynamic Function(FilePickerStatus)?) - Optional - A callback function that is invoked when a file starts loading. - **compressionQuality** (int) - Optional - The compression quality to use for picked images. Defaults to 0 (no compression). - **allowMultiple** (bool) - Optional - If true, allows the user to select multiple files. Defaults to false. - **withData** (bool) - Optional - If true, the file data will be included in the result. Defaults to false. - **withReadStream** (bool) - Optional - If true, a read stream for the file will be provided. Defaults to false. - **lockParentWindow** (bool) - Optional - If true, the parent window will be locked during selection. Defaults to false. - **readSequential** (bool) - Optional - If true, files will be read sequentially. Defaults to false. - **cancelUploadOnWindowBlur** (bool) - Optional - If true, file uploads will be cancelled when the window loses focus. Defaults to true. ### Returns - Future: A future that completes with a FilePickerResult object containing information about the picked files, or null if the user cancels the selection. ``` -------------------------------- ### pickFileAndDirectoryPaths Source: https://pub.dev/documentation/file_picker/latest/file_picker/FilePicker/pickFileAndDirectoryPaths.html Displays a dialog that allows the user to select both files and directories simultaneously, returning their absolute paths. Platform Support: As of right now, this functionality is only supported on macOS. ```APIDOC ## pickFileAndDirectoryPaths static method ### Description Displays a dialog that allows the user to select both files and directories simultaneously, returning their absolute paths. ### Platform Support macOS ### Parameters #### Optional Parameters - **initialDirectory** (String?) - The absolute path to specify where the dialog should open. On macOS, the home directory shortcut (~/) is not necessary and passing it will be ignored. If invalid, the user directory or previously valid directory will be used. - **type** (FileType) - Defaults to FileType.any. Filters the selectable items. - **allowedExtensions** (List?) - An optional list of file extensions to filter by (e.g., ["pdf", "svg", "jpg"]). ### Returns Future?> - A Future that resolves to a list of absolute paths for the selected files and directories. Returns `null` if the user cancels the dialog or if paths cannot be resolved. ```