### Installation Configuration Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/example/windows/CMakeLists.txt Configures installation paths and components for the application, ensuring that runtime files, data, libraries, and assets are correctly placed next to the executable. ```cmake set(BUILD_BUNDLE_DIR "$") set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" CONFIGURATIONS Profile;Release COMPONENT Runtime) ``` -------------------------------- ### PlatformFile Equality Example Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/api-reference/platform_file.md Demonstrates how to compare two PlatformFile objects for equality. ```dart PlatformFile file1 = PlatformFile(name: 'a.pdf', size: 100); PlatformFile file2 = PlatformFile(name: 'a.pdf', size: 100); if (file1 == file2) { print('Same file'); } ``` -------------------------------- ### PlatformFile toString() Example Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/api-reference/platform_file.md Shows how to print the debug string representation of a PlatformFile after picking a file. ```dart PlatformFile? file = await FilePicker.pickFile(); print(file); // PlatformFile(path /cache/file.pdf, name: file.pdf, bytesLength: null, readStream: false, size: 2048) ``` -------------------------------- ### Create PlatformFile Instance Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/api-reference/platform_file.md Example of creating a PlatformFile instance with essential properties like name, size, and path. ```dart final file = PlatformFile( name: 'document.pdf', size: 5120, path: '/cache/document.pdf', ); ``` -------------------------------- ### Installation Rules for Relocatable Bundle Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/example/linux/CMakeLists.txt Configures the installation process to create a relocatable application bundle. It cleans the build directory, installs the executable, ICU data, Flutter library, and bundled plugin libraries. ```cmake # === Installation === # By default, "installing" just makes a relocatable bundle in the build # directory. set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() # Start with a clean build bundle directory every time. install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) install(FILES "${bundled_library}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endforeach(bundled_library) # Fully re-copy the assets directory on each build to avoid having stale files ``` -------------------------------- ### Pick a Directory Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/README.md Example for selecting a directory. It returns the selected directory path or null if the user cancels. ```dart String? selectedDirectory = await FilePicker.getDirectoryPath(); if (selectedDirectory == null) { // User canceled the picker } ``` -------------------------------- ### File Picking Examples with FileType Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/types.md Demonstrates how to use the FileType enum to filter files during the picking process. Examples include picking any file, images, custom extensions, and media files. ```dart // Pick any file FilePickerResult? result = await FilePicker.pickFiles( type: FileType.any, ); ``` ```dart // Pick images only FilePickerResult? result = await FilePicker.pickFiles( type: FileType.image, ); ``` ```dart // Pick custom extensions FilePickerResult? result = await FilePicker.pickFiles( type: FileType.custom, allowedExtensions: ['pdf', 'doc', 'docx', 'xls', 'xlsx'], ); ``` ```dart // Pick media (images and videos) FilePickerResult? result = await FilePicker.pickFiles( type: FileType.media, ); ``` -------------------------------- ### Example of toMap() Output Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/api-reference/android_saf.md Illustrates the map representation of AndroidSAFOptions, including grant, access mode, and persistence settings. ```json { 'grant': 'lifetime', 'access': 'readWrite', 'autoPersist': true, } ``` -------------------------------- ### Example: Configuring AndroidSAFOptions for File Picking Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/types.md Shows how to create AndroidSAFOptions with lifetime grant, read-write access, and persistence enabled, then use them to pick files. ```dart // Create options for Android AndroidSAFOptions options = AndroidSAFOptions( grant: AndroidSAFGrant.lifetime, accessMode: AndroidSAFAccessMode.readWrite, persistGrant: true, ); // Use in file picker FilePickerResult? result = await FilePicker.pickFiles( androidSafOptions: options, ); ``` -------------------------------- ### FilePickerPlatform Singleton Usage Example Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/api-reference/file_picker_platform_interface.md Demonstrates how to use the default FilePickerPlatform instance or override it with a mock implementation for testing purposes. ```dart // Use default implementation FilePickerPlatform platform = FilePickerPlatform.instance; // Or override for testing class MockFilePickerPlatform extends FilePickerPlatform { @override Future pickFiles({...}) async { return null; } // ... implement other methods } FilePickerPlatform.instance = MockFilePickerPlatform(); ``` -------------------------------- ### Pick Multiple Files Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/README.md Example for selecting multiple files. It returns a list of file paths if successful, or indicates user cancellation. ```dart FilePickerResult? result = await FilePicker.pickFiles(allowMultiple: true); if (result != null) { List files = result.paths.map((path) => File(path!)).toList(); } else { // User canceled the picker } ``` -------------------------------- ### AndroidPlatformFile Example with SAF Handle Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/api-reference/platform_file.md Demonstrates picking files using SAF options and accessing the AndroidSAFHandle. It also shows how to release the grant when no longer needed. ```dart FilePickerResult? result = await FilePicker.pickFiles( androidSafOptions: AndroidSAFOptions( grant: AndroidSAFGrant.lifetime, ), ); if (result != null && result.files.first is AndroidPlatformFile) { AndroidPlatformFile androidFile = result.files.first as AndroidPlatformFile; AndroidSAFHandle handle = androidFile.safHandle; // Later, release the grant if no longer needed await handle.releaseGrant(); } ``` -------------------------------- ### Install Flutter Assets Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/example/linux/CMakeLists.txt Removes the old Flutter asset directory and installs the new one. This ensures that only the latest assets are present after an update. ```cmake set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install( CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Pick Multiple Custom Files Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/INDEX.md This example demonstrates how to pick multiple files of custom types, such as PDF and DOC. Specify allowed extensions using `allowedExtensions`. ```dart FilePickerResult? result = await FilePicker.pickFiles( allowMultiple: true, type: FileType.custom, allowedExtensions: ['pdf', 'doc'], ); ``` -------------------------------- ### Example: Persistent Lifetime Grant with AndroidSAFOptions Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/types.md Demonstrates how to configure AndroidSAFOptions for a persistent lifetime grant and read-write access mode when requesting a directory path. ```dart // Persistent lifetime grant AndroidSAFOptions options = AndroidSAFOptions( grant: AndroidSAFGrant.lifetime, accessMode: AndroidSAFAccessMode.readWrite, persistGrant: true, ); String? path = await FilePicker.getDirectoryPath( androidSafOptions: options, ); ``` -------------------------------- ### Release SAF Grant Example Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/types.md Demonstrates how to release a Storage Access Framework grant for a file if it is an AndroidPlatformFile. ```dart // Release a grant if (file is AndroidPlatformFile) { await file.safHandle.releaseGrant(); print('SAF grant released'); } ``` -------------------------------- ### Install AOT Library (Non-Debug Builds) Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/example/linux/CMakeLists.txt Installs the AOT (Ahead-Of-Time) library for the project, but only when the build type is not 'Debug'. This is typically used for release builds to improve performance. ```cmake if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### FilePickerResult Constructor Example Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/api-reference/file_picker_result.md Demonstrates how to manually create a FilePickerResult object with a list of PlatformFile objects. This is typically returned by FilePicker.pickFiles(). ```dart FilePickerResult result = FilePickerResult([ PlatformFile(name: 'file1.pdf', size: 1024, path: '/path/to/file1.pdf'), PlatformFile(name: 'file2.pdf', size: 2048, path: '/path/to/file2.pdf'), ]); ``` -------------------------------- ### Pick Single File Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/README.md A simple example to pick a single file. It prints the file name and size if a file is selected, otherwise indicates user cancellation. ```dart PlatformFile? file = await FilePicker.pickFile(); if (file != null) { print(file.name); print(file.size); } else { // User canceled the picker } ``` -------------------------------- ### AndroidSAFAccessMode Usage Example Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/types.md Shows how to request read-write access using AndroidSAFOptions when picking a directory on Android. Defaults to readOnly. ```dart // Request read-write access AndroidSAFOptions options = AndroidSAFOptions( accessMode: AndroidSAFAccessMode.readWrite, ); String? directory = await FilePicker.getDirectoryPath( androidSafOptions: options, ); ``` -------------------------------- ### Get Directory Path Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/INDEX.md Use `FilePicker.getDirectoryPath` to allow the user to select a directory. You can specify an initial directory. ```APIDOC ## Get Directory Path ### Description Allows the user to select a directory from their device. ### Method Signature `String? getDirectoryPath({String? initialDirectory, dynamic androidSafOptions})` ### Parameters - **initialDirectory** (String?) - Optional - The directory to open the picker in initially. - **androidSafOptions** (dynamic) - Optional - Options for Android's Storage Access Framework. ### Request Example ```dart String? dir = await FilePicker.getDirectoryPath( initialDirectory: '/home/user', ); ``` ### Response - **String?**: The path to the selected directory, or null if the user cancels the operation. ``` -------------------------------- ### Save File Example Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/api-reference/file_picker.md Demonstrates how to save file bytes to a user-selected location. Specify the file name, initial directory, and allowed extensions. Returns the saved file path or null if canceled. On web, this initiates a download and always returns null. ```dart Uint8List pdfBytes = await generatePdf(); String? filePath = await FilePicker.saveFile( fileName: 'document.pdf', bytes: pdfBytes, initialDirectory: '/home/user/Documents', type: FileType.custom, allowedExtensions: ['pdf'], ); if (filePath != null) { print('File saved to: $filePath'); } else { print('Save canceled'); } ``` ```dart // Web: automatically downloads the file if (kIsWeb) { await FilePicker.saveFile( fileName: 'export.xlsx', bytes: excelBytes, ); // Returns null; file is downloaded by the browser } else { // Desktop: shows save dialog String? path = await FilePicker.saveFile( fileName: 'export.xlsx', bytes: excelBytes, ); } ``` -------------------------------- ### Display AndroidSAFHandle URI Details Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/api-reference/android_saf.md Example of how to access and print the URI, scheme, and authority from an AndroidPlatformFile's SAF handle. ```dart if (file is AndroidPlatformFile) { Uri safUri = file.safHandle.uri; print('URI: $safUri'); print('Scheme: ${safUri.scheme}'); // 'content' print('Authority: ${safUri.authority}'); } ``` -------------------------------- ### Read-Write SAF Access Example Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/api-reference/android_saf.md Demonstrates requesting read and write access for a directory using Android SAF. This allows the app to persistently write files to the selected directory. ```dart // Request directory for exporting files AndroidSAFOptions options = AndroidSAFOptions( accessMode: AndroidSAFAccessMode.readWrite, grant: AndroidSAFGrant.lifetime, ); String? exportDir = await FilePicker.getDirectoryPath( androidSafOptions: options, ); // App can now write files to this directory persistently ``` -------------------------------- ### Read-Only SAF Access Example Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/api-reference/android_saf.md Shows how to pick files with read-only access using Android SAF. The access mode can be verified from the returned PlatformFile. ```dart // Pick files with read-only access AndroidSAFOptions options = AndroidSAFOptions( accessMode: AndroidSAFAccessMode.readOnly, ); FilePickerResult? result = await FilePicker.pickFiles( androidSafOptions: options, ); PlatformFile file = result!.files.first; if (file is AndroidPlatformFile) { print('Access mode: ${file.safHandle.accessMode}'); // Output: Access mode: AndroidSAFAccessMode.readOnly } ``` -------------------------------- ### Transient SAF Grant Example Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/api-reference/android_saf.md Demonstrates using a transient grant for a single file picking operation. This grant is revoked upon app restart. ```dart AndroidSAFOptions options = AndroidSAFOptions( grant: AndroidSAFGrant.transient, ); FilePickerResult? result = await FilePicker.pickFiles( androidSafOptions: options, ); // After app restart, this grant is no longer valid ``` -------------------------------- ### File Type Filtering Examples Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/REFERENCE.md Illustrates how to use the 'type' and 'allowedExtensions' parameters to filter files based on their type. Use 'FileType.custom' with 'allowedExtensions' for specific file formats. ```dart // Pick any file FilePickerResult? r = await FilePicker.pickFiles(type: FileType.any); ``` ```dart // Pick images FilePickerResult? r = await FilePicker.pickFiles(type: FileType.image); ``` ```dart // Pick videos FilePickerResult? r = await FilePicker.pickFiles(type: FileType.video); ``` ```dart // Pick media (images + videos) FilePickerResult? r = await FilePicker.pickFiles(type: FileType.media); ``` ```dart // Pick audio FilePickerResult? r = await FilePicker.pickFiles(type: FileType.audio); ``` ```dart // Pick custom extensions FilePickerResult? r = await FilePicker.pickFiles( type: FileType.custom, allowedExtensions: ['pdf', 'doc', 'docx', 'xls', 'xlsx'], ); ``` -------------------------------- ### File Picking with Minimal AndroidSAFOptions Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/configuration.md Example of picking files using Android SAF with all default options: transient grant, read-only access, and persistent grant set to true. ```dart // Uses all defaults: transient, readOnly, persistGrant=true FilePickerResult? result = await FilePicker.pickFiles( androidSafOptions: AndroidSAFOptions(), ); ``` -------------------------------- ### Configure Android SAF for Read/Write Access Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/INDEX.md This example configures Android's Storage Access Framework (SAF) for persistent read and write access to a directory. Use `AndroidSAFGrant.lifetime` for long-term access. ```dart String? dir = await FilePicker.getDirectoryPath( androidSafOptions: AndroidSAFOptions( grant: AndroidSAFGrant.lifetime, accessMode: AndroidSAFAccessMode.readWrite, ), ); ``` -------------------------------- ### Directory Picking with Persistent Read-Write Access Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/configuration.md Example of getting a directory path using Android SAF with persistent, read-write access. The grant will survive device reboots. ```dart AndroidSAFOptions options = AndroidSAFOptions( grant: AndroidSAFGrant.lifetime, accessMode: AndroidSAFAccessMode.readWrite, persistGrant: true, ); String? dirPath = await FilePicker.getDirectoryPath( androidSafOptions: options, ); ``` -------------------------------- ### Project and Build Configuration Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/example/linux/CMakeLists.txt Sets up the CMake minimum version, project name, and executable name. It also defines the application ID and configures modern CMake behaviors. ```cmake cmake_minimum_required(VERSION 3.10) project(runner LANGUAGES CXX) # The name of the executable created for the application. Change this to change # the on-disk name of your application. set(BINARY_NAME "example") # The unique GTK application identifier for this application. See: # https://wiki.gnome.org/HowDoI/ChooseApplicationID set(APPLICATION_ID "com.mr.flutter.plugin.filepicker.example") # Explicitly opt in to modern CMake behaviors to avoid warnings with recent # versions of CMake. cmake_policy(SET CMP0063 NEW) # Load bundled libraries from the lib/ directory relative to the binary. set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") # Root filesystem for cross-building. if(FLUTTER_TARGET_PLATFORM_SYSROOT) set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) endif() # Define build configuration options. if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Flutter build mode" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Profile" "Release") endif() ``` -------------------------------- ### Pick File and Directory Paths (macOS) Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/COMPLETION_SUMMARY.txt Illustrates how to pick both files and directory paths simultaneously, a feature specific to macOS. This is useful for workflows that involve selecting both individual items and their containing folders. ```dart final FilePickerResult? result = await FilePicker.platform.pickFileAndDirectoryPaths(); if (result != null) { final List paths = result.paths.whereType().toList(); // Process the paths } ``` -------------------------------- ### Handling IllegalCharacterInFileNameException Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/COMPLETION_SUMMARY.txt Provides an example of how to catch and handle `IllegalCharacterInFileNameException`, which may occur when saving files with invalid characters in their names. ```dart try { await FilePicker.platform.saveFile(fileName: 'invalid/name.txt', bytes: Uint8List(0)); } on IllegalCharacterInFileNameException catch (e) { print('Error saving file: ${e.message}'); } ``` -------------------------------- ### Instance Management Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/api-reference/file_picker_platform_interface.md Provides access to the current platform implementation instance and allows for overriding it, typically for testing purposes. ```APIDOC ## instance Property Gets or sets the current platform implementation instance. ```dart static FilePickerPlatform get instance => _instance; static set instance(FilePickerPlatform instance) { PlatformInterface.verifyToken(instance, _token); _instance = instance; } ``` ### Type `FilePickerPlatform` (read-write static property) ### Default Value `MethodChannelFilePicker()` — The default implementation using platform channels. ### Example ```dart // Use default implementation FilePickerPlatform platform = FilePickerPlatform.instance; // Or override for testing class MockFilePickerPlatform extends FilePickerPlatform { @override Future pickFiles({...}) async { return null; } // ... implement other methods } FilePickerPlatform.instance = MockFilePickerPlatform(); ``` ``` -------------------------------- ### Enable Desktop Platform Development Source: https://github.com/miguelpruivo/flutter_file_picker/wiki/Setup Commands to enable support for Windows, macOS, and Linux desktop development in Flutter. ```bash $ flutter config --enable-windows-desktop $ flutter config --enable-macos-desktop $ flutter config --enable-linux-desktop ``` -------------------------------- ### FilePickerStatus Usage Example Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/types.md Demonstrates how to use the FilePickerStatus enum in the onFileLoading callback to show loading indicators during file retrieval. ```dart FilePickerResult? result = await FilePicker.pickFiles( onFileLoading: (status) { if (status == FilePickerStatus.picking) { print('Files are being loaded...'); // Show loading indicator } else if (status == FilePickerStatus.done) { print('File loading complete'); // Hide loading indicator } }, ); ``` -------------------------------- ### Platform-Aware File Picking Patterns Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/REFERENCE.md This code illustrates how to handle file picking logic differently based on the target platform (web vs. IO, or specific platforms like Android and Windows). It shows how to load file data on the web and handle platform-specific options or exceptions. ```dart import 'package:flutter/foundation.dart'; // Web-specific if (kIsWeb) { FilePickerResult? result = await FilePicker.pickFiles( withData: true, // Load bytes ); Uint8List bytes = result!.files.first.bytes!; } else { // IO-specific FilePickerResult? result = await FilePicker.pickFiles(); List paths = result!.paths; } // Platform-specific if (defaultTargetPlatform == TargetPlatform.android) { String? dir = await FilePicker.getDirectoryPath( androidSafOptions: AndroidSAFOptions( grant: AndroidSAFGrant.lifetime, ), ); } if (defaultTargetPlatform == TargetPlatform.windows) { try { String? path = await FilePicker.getDirectoryPath(); } on WindowsException catch (e) { // Handle Windows-specific error } } ``` -------------------------------- ### Pick Files and Directories Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/api-reference/file_picker.md Use `pickFileAndDirectoryPaths` to open a native picker for selecting files and directories simultaneously. This method is currently only supported on macOS and returns absolute paths as strings. ```dart static Future?> pickFileAndDirectoryPaths({ String? dialogTitle, String? initialDirectory, FileType type = FileType.any, List? allowedExtensions, }) ``` ```dart // Pick files and directories on macOS List? paths = await FilePicker.pickFileAndDirectoryPaths( dialogTitle: 'Select files or folders', initialDirectory: '/Users/user/Documents', ); if (paths != null) { for (String path in paths) { print('Selected: $path'); } } ``` -------------------------------- ### Check AndroidSAFHandle Access Mode Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/api-reference/android_saf.md Example of how to check the access mode of an AndroidPlatformFile's SAF handle to determine if the file can be modified. ```dart PlatformFile file = result!.files.first; if (file is AndroidPlatformFile) { AndroidSAFAccessMode mode = file.safHandle.accessMode; if (mode == AndroidSAFAccessMode.readWrite) { print('Can modify file'); } else { print('Read-only access'); } } ``` -------------------------------- ### Select a Directory Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/REFERENCE.md Use `FilePicker.getDirectoryPath` to allow users to select a directory. You can specify an `initialDirectory` to pre-select a location. ```dart String? selectedDir = await FilePicker.getDirectoryPath( initialDirectory: '/home/user/Documents', ); if (selectedDir != null) { print('Selected: $selectedDir'); } ``` -------------------------------- ### Constructor Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/api-reference/file_picker_result.md Initializes a new instance of the FilePickerResult class with a list of PlatformFile objects. ```APIDOC ## Constructor ```dart const FilePickerResult(this.files) ``` ### Parameters | Parameter | Type | Required | Description | |-----------|------|----------|-------------| | files | List | Yes | List of selected files. | ### Example ```dart // Typically returned by FilePicker.pickFiles() FilePickerResult result = FilePickerResult([ PlatformFile(name: 'file1.pdf', size: 1024, path: '/path/to/file1.pdf'), PlatformFile(name: 'file2.pdf', size: 2048, path: '/path/to/file2.pdf'), ]); ``` ``` -------------------------------- ### Get File Size Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/COMPLETION_SUMMARY.txt Shows how to retrieve the size of a `PlatformFile` in bytes. This is useful for displaying file information or performing size-based operations. ```dart final int size = file.size; ``` -------------------------------- ### Project and Build Configuration Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/example/windows/CMakeLists.txt Sets up the minimum CMake version, project name, and executable name. It also configures build types for multi-configuration generators and sets the default build type if not specified. ```cmake cmake_minimum_required(VERSION 3.14) project(example LANGUAGES CXX) set(BINARY_NAME "example") cmake_policy(SET CMP0063 NEW) get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) if(IS_MULTICONFIG) set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" CACHE STRING "" FORCE) else() if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Flutter build mode" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Profile" "Release") endif() endif() ``` -------------------------------- ### Export Flutter Library and ICU Data Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/example/windows/flutter/CMakeLists.txt Publishes the Flutter library path and the ICU data file to the parent scope for use in the install step. ```cmake set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) ``` -------------------------------- ### Select Directory Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/INDEX.md Use this to prompt the user to select a directory. You can specify an initial directory to open the picker in. ```dart String? dir = await FilePicker.getDirectoryPath( initialDirectory: '/home/user', ); ``` -------------------------------- ### Configuration Reference Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/REFERENCE.md Detailed reference for all parameters available for file picker methods, including platform support and default values. ```APIDOC ## Configuration Reference ### Description Provides details on all parameters for file picker methods, including platform support and default values. ``` -------------------------------- ### Basic File Selection with SAF Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/api-reference/android_saf.md Demonstrates how to pick files using Android SAF, specifying grant type and access mode. It also shows how to access SAF-specific properties like the URI and access mode from the returned `AndroidPlatformFile`. ```APIDOC ## Basic File Selection with SAF ```dart // Pick files with Android SAF FilePickerResult? result = await FilePicker.pickFiles( androidSafOptions: AndroidSAFOptions( grant: AndroidSAFGrant.transient, accessMode: AndroidSAFAccessMode.readOnly, ), ); if (result != null) { for (PlatformFile file in result.files) { print('File: ${file.name}'); if (file is AndroidPlatformFile) { print('SAF URI: ${file.safHandle.uri}'); print('Access: ${file.safHandle.accessMode}'); } } } ``` ``` -------------------------------- ### Pick Files with Flutter File Picker Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/COMPLETION_SUMMARY.txt Demonstrates the basic usage of picking multiple files using the `pickFiles` method. This is suitable for scenarios where users need to select one or more files. ```dart final List? paths = (await FilePicker.platform.pickFiles())?.files; if (paths != null && paths.isNotEmpty) { // Process the selected files } ``` -------------------------------- ### Handle WindowsException in FilePicker Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/errors.md Catch Windows-specific errors when getting a directory path. This is useful for handling dialog instantiation or result parsing issues on Windows. ```dart try { String? directory = await FilePicker.getDirectoryPath(); } on WindowsException catch (e) { print('Windows error: ${e.message}'); // Likely dialog initialization or result parsing issue } on PlatformException catch (e) { print('Platform error: ${e.code} - ${e.message}'); } ``` -------------------------------- ### Pick Files and Directories Simultaneously Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/api-reference/file_picker_platform_interface.md Use this method to display a dialog that allows users to select both files and directories at the same time. This functionality is only supported on macOS. ```dart Future?> pickFileAndDirectoryPaths({ String? dialogTitle, String? initialDirectory, FileType type = FileType.any, List? allowedExtensions, }) ``` -------------------------------- ### Lifetime SAF Grant Example Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/api-reference/android_saf.md Illustrates using a lifetime grant with persistent storage enabled for directory access. This grant survives app and device restarts. ```dart AndroidSAFOptions options = AndroidSAFOptions( grant: AndroidSAFGrant.lifetime, persistGrant: true, ); String? docDir = await FilePicker.getDirectoryPath( androidSafOptions: options, ); // Later, after app restart: String? docDir2 = await FilePicker.getDirectoryPath( androidSafOptions: AndroidSAFOptions( grant: AndroidSAFGrant.lifetime, ), ); // Can access the same directory again without user interaction ``` -------------------------------- ### Mocking File Picker for Unit Tests Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/REFERENCE.md This snippet demonstrates how to create a mock implementation of FilePickerPlatform for unit testing. It allows you to simulate file picking behavior without interacting with the actual file system. Ensure you set up the mock before running your tests. ```dart import 'package:file_picker/file_picker.dart'; class MockFilePickerPlatform extends FilePickerPlatform { @override Future pickFiles({...}) async { return FilePickerResult([ PlatformFile( name: 'test.pdf', size: 1024, path: '/cache/test.pdf', ), ]); } // Implement other methods... } void main() { setUp(() { FilePickerPlatform.instance = MockFilePickerPlatform(); }); test('can pick file', () async { PlatformFile? file = await FilePicker.pickFile(); expect(file?.name, 'test.pdf'); }); } ``` -------------------------------- ### Read File as Byte Stream Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/COMPLETION_SUMMARY.txt Demonstrates how to read the content of a `PlatformFile` as a byte stream. This is efficient for handling large files without loading the entire content into memory. ```dart final Stream> byteStream = file.readStream!; // Use ! because readStream is nullable // Process the stream ``` -------------------------------- ### pickFileAndDirectoryPaths() Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/api-reference/file_picker_platform_interface.md Displays a dialog for selecting both files and directories simultaneously. This method is only implemented on macOS. ```APIDOC ## pickFileAndDirectoryPaths() ### Description Displays a dialog for selecting both files and directories simultaneously. ### Method Signature `Future?> pickFileAndDirectoryPaths({ String? dialogTitle, String? initialDirectory, FileType type = FileType.any, List? allowedExtensions, })` ### Parameters #### Optional Parameters - **dialogTitle** (String?) - Description: Dialog title. - **initialDirectory** (String?) - Description: Starting directory. - **type** (FileType) - Default: FileType.any - Description: File type filter. - **allowedExtensions** (List?) - Description: Custom extensions for `FileType.custom`. ### Return Type `Future?>` — List of absolute paths (files and/or directories), or `null` if user canceled. ### Throws `UnimplementedError` — Base class throws this; only macOS implements this method. ### Platform Support Only macOS implements this method. All other platforms throw `UnimplementedError`. ``` -------------------------------- ### File Picking with Read-Only Transient Access Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/configuration.md Example of picking files using Android SAF with default transient, read-only access. The grant will not persist after the current request. ```dart AndroidSAFOptions options = AndroidSAFOptions( grant: AndroidSAFGrant.transient, accessMode: AndroidSAFAccessMode.readOnly, persistGrant: true, ); FilePickerResult? result = await FilePicker.pickFiles( androidSafOptions: options, ); ``` -------------------------------- ### Pick Multiple Files with Extension Filter Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/README.md Demonstrates how to pick multiple files while restricting the selection to specific file types using the 'allowedExtensions' parameter. ```dart FilePickerResult? result = await FilePicker.pickFiles( allowMultiple: true, type: FileType.custom, allowedExtensions: ['jpg', 'pdf', 'doc'], ); ``` -------------------------------- ### Pick and Upload File to Firebase Storage (Flutter Web) Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/README.md Example for picking a file and then uploading its bytes to Firebase Storage. This is particularly relevant for Flutter Web applications. ```dart FilePickerResult? result = await FilePicker.pickFiles(); if (result != null) { Uint8List fileBytes = result.files.first.bytes; String fileName = result.files.first.name; // Upload file await FirebaseStorage.instance.ref('uploads/$fileName').putData(fileBytes); } ``` -------------------------------- ### Platform-Aware File Access (Web vs. IO) Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/errors.md This code demonstrates how to conditionally handle file access based on the platform. Use bytes/stream on Web and paths for IO platforms. ```dart import 'package:flutter/foundation.dart'; if (kIsWeb) { // Web: use bytes/stream for (PlatformFile file in result.files) { Uint8List bytes = await file.readAsBytes(); } } else { // IO: use paths List paths = result.paths; for (String? path in paths) { File ioFile = File(path!); } } ``` -------------------------------- ### Define Flutter library and headers Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/example/linux/flutter/CMakeLists.txt Sets the path to the Flutter Linux GTK shared library and its associated header files. These are published to the parent scope for use in installation steps. ```cmake set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") # Published to parent scope for install step. set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) ``` -------------------------------- ### iOS Pods Deintegration and Reinstallation Source: https://github.com/miguelpruivo/flutter_file_picker/wiki/Troubleshooting Run these commands in the 'ios' directory to resolve dependency caching issues. ```bash pod deintegrate && rm Podfile.lock && pod install ``` -------------------------------- ### Retrieve Files as XFiles or Individually Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/README.md Shows how to access picked files as a list of XFiles or individually from the result. ```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 } ``` -------------------------------- ### Accessing File Size Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/api-reference/platform_file.md Get the file size in bytes using the `size` property. It defaults to 0 if the size cannot be determined and is always available unless explicitly set to 0. ```dart final int size ``` ```dart PlatformFile? file = await FilePicker.pickFile(); print('File size: ${file?.size} bytes'); ``` -------------------------------- ### Pick Files and Stream Large Files Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/INDEX.md Demonstrates how to pick files and then stream large files chunk by chunk instead of loading the entire file into memory. This is useful for uploading or processing large files efficiently. ```dart FilePickerResult? result = await FilePicker.pickFiles(); if (result != null) { PlatformFile file = result.files.first; // Stream large files instead of loading all at once await for (Uint8List chunk in file.readAsByteStream()) { // Upload or process chunk } } ``` -------------------------------- ### WithData Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/COMPLETION_SUMMARY.txt Shows how to retrieve the file content as bytes directly when picking files. This is useful if you need to access the file data immediately after selection without needing to read it from disk. ```dart final List? paths = (await FilePicker.platform.pickFiles(withData: true))?.files; if (paths != null && paths.isNotEmpty) { final Uint8List? fileBytes = paths.first.bytes; } ``` -------------------------------- ### Accessing File Bytes on Web Source: https://github.com/miguelpruivo/flutter_file_picker/wiki/FAQ On web platforms, direct file paths are not available. Use this snippet to get file bytes for uploading to services like Firebase Storage. ```dart final result = await FilePicker.platform.pickFiles(type: FileType.any, allowMultiple: false); if (result != null && result.files.isNotEmpty) { final fileBytes = result.files.first.bytes; final fileName = result.files.first.name; // upload file await FirebaseStorage.instance.ref('uploads/$fileName').putData(fileBytes); } ``` -------------------------------- ### Uploading Large Files with Read Stream Source: https://github.com/miguelpruivo/flutter_file_picker/wiki/FAQ For large files, use `withReadStream` to upload them in chunks. This example demonstrates uploading a file via HTTP POST using a byte stream. ```dart import 'package:file_picker/file_picker.dart'; import 'package:http/http.dart' as http; import 'package:http_parser/http_parser.dart'; import 'package:mime/mime.dart'; void main() async { final result = await FilePicker.platform.pickFiles( type: FileType.custom, allowedExtensions: [ 'jpg', 'png', 'mp4', 'webm', ], withData: false, withReadStream: true, ); if (result == null || result.files.isEmpty) { throw Exception('No files picked or file picker was canceled'); } final file = result.files.first; final filePath = file.path; final mimeType = filePath != null ? lookupMimeType(filePath) : null; final contentType = mimeType != null ? MediaType.parse(mimeType) : null; final fileReadStream = file.readStream; if (fileReadStream == null) { throw Exception('Cannot read file from null stream'); } final stream = http.ByteStream(fileReadStream); final uri = Uri.https('siasky.net', '/skynet/skyfile'); final request = http.MultipartRequest('POST', uri); final multipartFile = http.MultipartFile( 'file', stream, file.size, filename: file.name, contentType: contentType, ); request.files.add(multipartFile); final httpClient = http.Client(); final response = await httpClient.send(request); if (response.statusCode != 200) { throw Exception('HTTP ${response.statusCode}'); } final body = await response.stream.transform(utf8.decoder).join(); print(body); } ``` -------------------------------- ### List Core C++ Wrapper Sources Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/example/windows/flutter/CMakeLists.txt Appends core C++ client wrapper source filenames to a list and then prepends the wrapper root directory path to each. ```cmake list(APPEND CPP_WRAPPER_SOURCES_CORE "core_implementations.cc" "standard_codec.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") ``` -------------------------------- ### Basic File Selection with Android SAF Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/api-reference/android_saf.md Demonstrates picking files using Android SAF with transient read-only access. It iterates through the selected files, printing their names and SAF URI and access mode if they are AndroidPlatformFile instances. ```dart // Pick files with Android SAF FilePickerResult? result = await FilePicker.pickFiles( androidSafOptions: AndroidSAFOptions( grant: AndroidSAFGrant.transient, accessMode: AndroidSAFAccessMode.readOnly, ), ); if (result != null) { for (PlatformFile file in result.files) { print('File: ${file.name}'); if (file is AndroidPlatformFile) { print('SAF URI: ${file.safHandle.uri}'); print('Access: ${file.safHandle.accessMode}'); } } } ``` -------------------------------- ### Get Directory Path Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/api-reference/file_picker_platform_interface.md Selects a directory and returns its absolute path. Use this to allow users to choose a folder. Returns null if the user cancels the operation. Supported on all non-Web platforms. ```dart Future getDirectoryPath({ String? dialogTitle, bool lockParentWindow = false, String? initialDirectory, AndroidSAFOptions? androidSafOptions, }) ``` -------------------------------- ### Getting the Count of Selected Files Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/api-reference/file_picker_result.md Retrieves and prints the total number of files selected in a file picking operation using the `count` getter. This is useful for displaying a summary of selected files. ```dart FilePickerResult? result = await FilePicker.pickFiles(allowMultiple: true); if (result != null) { print('Selected $${result.count} files'); } ``` -------------------------------- ### FilePicker.pickFile() Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/configuration.md Picks a single file. It omits parameters like allowMultiple, withData, withReadStream, and readSequential, and always returns a single PlatformFile?. ```APIDOC ## FilePicker.pickFile() ### Description Picks a single file from the device. This method is a simplified version of `pickFiles()`. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **dialogTitle** (String?) - Optional - Custom dialog title (Linux, Windows). - **initialDirectory** (String?) - Optional - Starting directory path. - **type** (FileType) - Optional - File type filter. Defaults to `FileType.any`. - **allowedExtensions** (List?) - Optional - Custom extensions for `FileType.custom`. - **onFileLoading** (Function(FilePickerStatus)?) - Optional - Loading status callback. - **compressionQuality** (int) - Optional - Image compression quality (0-100). Defaults to 0. - **lockParentWindow** (bool) - Optional - Modal behavior (Windows). Defaults to false. - **cancelUploadOnWindowBlur** (bool) - Optional - Web-specific upload behavior. Defaults to true. - **androidSafOptions** (AndroidSAFOptions?) - Optional - Android SAF configuration. ``` -------------------------------- ### Enable AndroidX Migration Source: https://github.com/miguelpruivo/flutter_file_picker/wiki/Troubleshooting Add these lines to your android/gradle.properties file to enable AndroidX support. ```gradle android.useAndroidX=true android.enableJetifier=true ``` -------------------------------- ### Get Directory Path with Flutter File Picker Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/COMPLETION_SUMMARY.txt Demonstrates how to use `getDirectoryPath` to allow users to select a directory. This is ideal for operations that require a target folder, such as saving files or organizing data. ```dart final String? directory = await FilePicker.platform.getDirectoryPath(); if (directory != null) { // Process the selected directory } ``` -------------------------------- ### List Application C++ Wrapper Sources Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/example/windows/flutter/CMakeLists.txt Appends application runner-specific C++ client wrapper source filenames to a list and then prepends the wrapper root directory path to each. ```cmake list(APPEND CPP_WRAPPER_SOURCES_APP "flutter_engine.cc" "flutter_view_controller.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") ``` -------------------------------- ### Accessing File Path Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/api-reference/platform_file.md Use the `path` property to get the absolute filesystem path to the file. This is useful for creating `dart:io` File instances. Note that `path` can be null on Android when using SAF without caching. ```dart final String? path ``` ```dart PlatformFile? file = await FilePicker.pickFile(); if (file?.path != null) { File ioFile = File(file!.path!); bool exists = await ioFile.exists(); } ``` -------------------------------- ### Pick Any File Source: https://github.com/miguelpruivo/flutter_file_picker/wiki/API Lets the user pick one file of any type. The result will be null if the user aborts the dialog. ```dart FilePickerResult result = await FilePicker.platform.pickFiles(type: FileType.any); // The result will be null, if the user aborted the dialog if(result != null) { File file = File(result.files.first.path); } ``` -------------------------------- ### Get File Size in Bytes Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/api-reference/platform_file.md Retrieves the size of the file in bytes. This method provides a fallback mechanism to determine file size when the 'size' property is not directly available. It attempts to use other properties or methods if the primary 'size' property is unavailable. ```dart PlatformFile? file = await FilePicker.pickFile(); if (file != null) { int fileSize = await file.length(); print('File length: $fileSize bytes'); } ``` -------------------------------- ### Accessing File Paths Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/api-reference/file_picker_result.md Retrieves a list of absolute paths for all selected files using the `paths` getter. This example also includes a check for `kIsWeb` and demonstrates creating a File object to check its existence. Note that this getter is only supported on IO platforms and throws an `UnsupportedError` on Web. ```dart FilePickerResult? result = await FilePicker.pickFiles(allowMultiple: true); if (result != null && !kIsWeb) { List paths = result.paths; for (String? path in paths) { File file = File(path!); print('File exists: ${file.existsSync()}'); } } ``` -------------------------------- ### PlatformFile Constructor Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/api-reference/platform_file.md Instantiates a PlatformFile object with basic file metadata. Use this when you have the file's name, size, and optionally its path, bytes, or stream. ```dart PlatformFile({ this.path, required this.name, required this.size, this.bytes, this.readStream, this.identifier, }) ``` -------------------------------- ### Add Dependency Libraries and Include Directories Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/example/windows/runner/CMakeLists.txt Links necessary libraries (flutter, flutter_wrapper_app, dwmapi.lib) and specifies include directories for the project. Custom application dependencies can also be added here. ```cmake # Add dependency libraries and include directories. Add any application-specific # dependencies here. target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib") target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") ``` -------------------------------- ### Allow Multiple File Selection Source: https://github.com/miguelpruivo/flutter_file_picker/blob/master/_autodocs/COMPLETION_SUMMARY.txt Shows how to enable multiple file selection by setting `allowMultiple` to `true`. This is the default behavior when `pickFiles` is used without specifying `allowMultiple`. ```dart final List? paths = (await FilePicker.platform.pickFiles(allowMultiple: true))?.files; ```