### Installation Rules Source: https://github.com/incrediblezayed/file_saver/blob/main/example/windows/CMakeLists.txt Defines installation directories and files for the application, including runtime components and assets. ```cmake # === Installation === # Support files are copied into place next to the executable, so that it can # run in place. This is done instead of making a separate bundle (as on Linux) # so that building and running from within Visual Studio will work. set(BUILD_BUNDLE_DIR "$") # Make the "install" step default, as it's required to run. 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() # Fully re-copy the assets directory on each build to avoid having stale files # from a previous install. 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 the AOT library on non-Debug builds only. install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" CONFIGURATIONS Profile;Release COMPONENT Runtime) ``` -------------------------------- ### Basic CMake Setup Source: https://github.com/incrediblezayed/file_saver/blob/main/example/windows/CMakeLists.txt Sets the minimum CMake version, project name, and binary name. Configures installation paths and build types. ```cmake cmake_minimum_required(VERSION 3.15) project(file_saver_example LANGUAGES CXX) set(BINARY_NAME "file_saver_example") cmake_policy(SET CMP0063 NEW) set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") # Configure build options. 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() set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") # Use Unicode for all projects. add_definitions(-DUNICODE -D_UNICODE) # Compilation settings that should be applied to most targets. function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_17) target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") target_compile_options(${TARGET} PRIVATE /EHsc) target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") endfunction() set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") # Flutter library and tool build rules. add_subdirectory(${FLUTTER_MANAGED_DIR}) # Application build add_subdirectory("runner") # Generated plugin build rules, which manage building the plugins and adding # them to the application. include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/incrediblezayed/file_saver/blob/main/linux/CMakeLists.txt Sets the minimum CMake version, project name, and languages. This is a standard starting point for CMake projects. ```cmake cmake_minimum_required(VERSION 3.10) set(PROJECT_NAME "file_saver") project(${PROJECT_NAME} LANGUAGES CXX) ``` -------------------------------- ### Installation Rules for Runtime Bundle Source: https://github.com/incrediblezayed/file_saver/blob/main/example/linux/CMakeLists.txt Configures installation to create a relocatable bundle in the build directory, including executable, data, and 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) if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() # Fully re-copy the assets directory on each build to avoid having stale files # from a previous install. 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 the AOT library on non-Debug builds only. if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Example Usage of getFilePathSlash Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/Helpers.md Shows how to use getFilePathSlash to create a platform-independent full file path. ```dart final slash = Helpers.getFilePathSlash(); final fullPath = '$directory$slash$filename'; // On all platforms: '/path/to/directory/filename' ``` -------------------------------- ### Basic CMake Setup Source: https://github.com/incrediblezayed/file_saver/blob/main/example/windows/flutter/CMakeLists.txt Initializes CMake version and defines the ephemeral directory. Includes generated configuration and sets up fallback platforms. ```cmake cmake_minimum_required(VERSION 3.15) set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") # Configuration provided via flutter tool. include(${EPHEMERAL_DIR}/generated_config.cmake) # TODO: Move the rest of this into files in ephemeral. See # https://github.com/flutter/flutter/issues/57146. set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") # Set fallback configurations for older versions of the flutter tool. if (NOT DEFINED FLUTTER_TARGET_PLATFORM) set(FLUTTER_TARGET_PLATFORM "windows-x64") endif() ``` -------------------------------- ### Example Usage of getDirectory Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/Helpers.md Demonstrates internal usage of the getDirectory method to construct a full file path. ```dart final dir = await Helpers.getDirectory(); if (dir != null) { final filepath = '$dir/${fileName}${fileExtension}'; } ``` -------------------------------- ### Download with Authentication Example Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/FileSaver.md Demonstrates how to download a private resource using authentication headers and specifying the file extension and MIME type. ```dart await FileSaver.instance.saveLinkAsStream( name: 'private-export', link: LinkDetails( link: 'https://api.example.com/private/export.zip', headers: {'Authorization': 'Bearer my-token'}, method: 'GET', ), fileExtension: 'zip', mimeType: MimeType.zip, includeCredentials: true, ); ``` -------------------------------- ### Example Usage of getExtension Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/Helpers.md Illustrates how to use the getExtension method with different inputs to format file extensions. ```dart Helpers.getExtension(fileExtension: 'pdf') // Returns: '.pdf' Helpers.getExtension(fileExtension: '.pdf') // Returns: '.pdf' Helpers.getExtension(fileExtension: '') // Returns: '' Helpers.getExtension(fileExtension: 'tar.gz') // Returns: 'tar.gz' ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/incrediblezayed/file_saver/blob/main/example/linux/CMakeLists.txt Sets the minimum CMake version, project name, and languages. Configures application ID and build type. ```cmake cmake_minimum_required(VERSION 3.10) project(runner LANGUAGES CXX) set(BINARY_NAME "file_saver_example") set(APPLICATION_ID "com.one.file_saver") cmake_policy(SET CMP0063 NEW) 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() # Configure build 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() ``` -------------------------------- ### Web CORS Requirements Example Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/configuration.md Example of required CORS headers for authenticated downloads with saveLinkAsStream. Ensure your server responds with these headers. ```text Access-Control-Allow-Origin: https://yourapp.example.com Access-Control-Allow-Methods: GET, POST, OPTIONS Access-Control-Allow-Headers: Authorization, Content-Type ``` -------------------------------- ### Download on Native Platform Example Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/FileSaver.md Shows how to download a file on a native platform, including custom headers like User-Agent and specifying the file extension and MIME type. ```dart await FileSaver.instance.saveLinkAsStream( name: 'report', link: LinkDetails( link: 'https://reports.example.com/q4.pdf', headers: {'User-Agent': 'MyApp/1.0'}, ), fileExtension: 'pdf', mimeType: MimeType.pdf, ); ``` -------------------------------- ### LinkDetails Constructor Example Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/LinkDetails.md Demonstrates creating a LinkDetails object with custom headers, method, body, and query parameters for a POST request. ```dart final link = LinkDetails( link: 'https://api.example.com/v1/export', headers: {'Authorization': 'Bearer abc123'}, method: 'POST', body: {'format': 'pdf', 'id': 'doc-456'}, queryParameters: {'version': '2'}, ); ``` -------------------------------- ### CMake Project Configuration Source: https://github.com/incrediblezayed/file_saver/blob/main/example/windows/runner/CMakeLists.txt Sets the minimum CMake version and project name. This is a standard starting point for CMake projects. ```cmake cmake_minimum_required(VERSION 3.15) project(runner LANGUAGES CXX) ``` -------------------------------- ### LinkDetails toString Example Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/LinkDetails.md Shows the string representation of a LinkDetails object, useful for debugging and logging. ```dart final link = LinkDetails( link: 'https://example.com/file.pdf', headers: {'Authorization': 'Bearer token'}, ); print(link.toString()); // Output: LinkDetails(link: https://example.com/file.pdf, method: GET, body: null, headers: {Authorization: Bearer token}, queryParameters: null, responseType: ResponseType.bytes) ``` -------------------------------- ### LinkDetails hashCode Example Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/LinkDetails.md Demonstrates how LinkDetails objects with identical properties are treated as equal in sets, ensuring uniqueness. ```dart final link1 = LinkDetails(link: 'https://example.com'); final link2 = LinkDetails(link: 'https://example.com'); final set = {link1, link2}; print(set.length); // Output: 1 (both are considered identical) ``` -------------------------------- ### Example MethodChannel invokeMethod Usage Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/PlatformHandler.md Demonstrates how to invoke a MethodChannel method and handle the returned string, providing an empty string as a default if the result is null. ```dart final String result = await _channel.invokeMethod( 'saveFile', fileModel.toMap(), ) ?? ''; ``` -------------------------------- ### Save File with LinkDetails Source: https://github.com/incrediblezayed/file_saver/blob/main/README.md This is a specific example of using the saveFile method with the LinkDetails parameter to download a file from a URL, including optional headers, method, and body. ```dart LinkDetails( link: "https://www.example.com/file.extentions", headers: {"your-header-key": "you-header-value"}, method: "POST", body: body ) ``` -------------------------------- ### Stream from HTTP Response Body Example Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/FileSaver.md Shows how to save a file by streaming its content directly from an HTTP response body, specifying the filename, extension, and MIME type. ```dart final response = await dio.request( 'https://example.com/large-file', options: Options(responseType: ResponseType.stream), ); await FileSaver.instance.saveAsStream( name: 'downloaded_file', stream: response.data!.stream, fileExtension: 'zip', mimeType: MimeType.zip, ); ``` -------------------------------- ### Flutter Library Target Setup Source: https://github.com/incrediblezayed/file_saver/blob/main/example/linux/flutter/CMakeLists.txt Configures the 'flutter' interface library target, including setting include directories and linking against system libraries and the Flutter shared library. ```cmake list(APPEND FLUTTER_LIBRARY_HEADERS "fl_basic_message_channel.h" "fl_binary_codec.h" "fl_binary_messenger.h" "fl_dart_project.h" "fl_engine.h" "fl_json_message_codec.h" "fl_json_method_codec.h" "fl_message_codec.h" "fl_method_call.h" "fl_method_channel.h" "fl_method_codec.h" "fl_method_response.h" "fl_plugin_registrar.h" "fl_plugin_registry.h" "fl_standard_message_codec.h" "fl_standard_method_codec.h" "fl_string_codec.h" "fl_value.h" "fl_view.h" "flutter_linux.h" ) list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") add_library(flutter INTERFACE) target_include_directories(flutter INTERFACE "${EPHEMERAL_DIR}" ) target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") target_link_libraries(flutter INTERFACE PkgConfig::GTK PkgConfig::GLIB PkgConfig::GIO ) add_dependencies(flutter flutter_assemble) ``` -------------------------------- ### Download Link (Web) Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/PlatformHandler.md Uses the browser's native download mechanism for simple GET URLs on the web. Returns 'Downloads' on success, null otherwise. ```dart @override Future downloadLink(LinkDetails link, {String? name}) async { final result = FileSaverWeb.downloadLink(link.link, name: name); if (result) { return 'Downloads'; } return null; } ``` -------------------------------- ### Save App-Generated Stream Example Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/FileSaver.md Demonstrates saving a stream of bytes generated by the application, specifying the filename, extension, and MIME type. ```dart final byteStream = _generateLargeFile(); // Returns Stream> await FileSaver.instance.saveAsStream( name: 'generated_report', stream: byteStream, fileExtension: 'csv', mimeType: MimeType.csv, ); ``` -------------------------------- ### Request Storage Permissions Before Saving Files Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/errors.md Before saving files on native platforms, ensure you have the necessary storage permissions. This example demonstrates requesting 'storage' permission using the 'permission_handler' package. ```dart import 'package:permission_handler/permission_handler'; if (await Permission.storage.request().isGranted) { await FileSaver.instance.saveFile( name: 'document', bytes: bytes, fileExtension: 'pdf', mimeType: MimeType.pdf, ); } else { print('Storage permission denied'); } ``` -------------------------------- ### Format File Extension Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/Helpers.md Ensures a file extension string starts with a leading dot. Handles cases with and without existing dots, and empty strings. ```dart static String getExtension({required String fileExtension}) ``` -------------------------------- ### downloadLink Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/PlatformHandler.md Initiates a file download using the browser's native download mechanism for simple GET URLs. This method is primarily supported on Android and web platforms. ```APIDOC ## downloadLink ### Description Downloads a file from a given URL using the browser's native download functionality or Android's DownloadManager. ### Method GET (Implied by downloading a link) ### Endpoint Not applicable (SDK method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **link** (LinkDetails) - Required - An object containing the URL and optional headers for the download. - **name** (String?) - Optional - The desired name for the downloaded file. ### Request Example ```json { "link": { "link": "https://example.com/file.zip", "headers": { "Authorization": "Bearer token" } }, "name": "downloaded_file.zip" } ``` ### Response #### Success Response (200) - **path** (String?) - A confirmation message or path related to the download initiation, or null if the download could not be started. #### Response Example ```json "Downloads" ``` ``` -------------------------------- ### Download File via Link (Dart) Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/FileSaver.md Hands off a URL to the system download manager for memory-efficient downloads. Supported on Web and Android. Ensure the URL supports GET requests without custom headers or bodies on the web. ```dart Future downloadLink({ required LinkDetails link, String? name, }) ``` ```dart await FileSaver.instance.downloadLink( link: LinkDetails(link: 'https://cdn.example.com/large-archive.zip'), name: 'large-archive.zip', ); ``` ```dart await FileSaver.instance.downloadLink( link: LinkDetails( link: 'https://api.example.com/file?token=signed-url', headers: {'Authorization': 'Bearer token'}, ), name: 'secure-download.pdf', ); ``` -------------------------------- ### FileModel fileExtension Property Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/FileModel.md Gets the file extension, typically starting with a dot (e.g., '.pdf'). Can be an empty string if no extension is specified. ```dart final String fileExtension ``` ```dart print(model.fileExtension); // Output: .pdf ``` -------------------------------- ### Get Default Save Directory Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/Helpers.md Gets the platform-specific default directory for saving files, utilizing the 'path_provider' package. Returns null for web platforms. ```dart static Future getDirectory() ``` -------------------------------- ### Get FileSaver Instance Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/FileSaver.md Access the singleton instance of the FileSaver class to perform file operations. ```dart final fileSaver = FileSaver.instance; ``` -------------------------------- ### Application Build Configuration Source: https://github.com/incrediblezayed/file_saver/blob/main/example/linux/CMakeLists.txt Defines the main executable, applies standard settings, links libraries, and sets runtime output directory. ```cmake # Application build add_executable(${BINARY_NAME} "main.cc" "my_application.cc" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" ) apply_standard_settings(${BINARY_NAME}) target_link_libraries(${BINARY_NAME} PRIVATE flutter) target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) add_dependencies(${BINARY_NAME} flutter_assemble) # Only the install-generated bundle's copy of the executable will launch # correctly, since the resources must in the right relative locations. To avoid # people trying to run the unbundled copy, put it in a subdirectory instead of # the default top-level location. set_target_properties(${BINARY_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" ) ``` -------------------------------- ### LinkDetails Constructor Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/LinkDetails.md Creates a LinkDetails object for configuring remote file downloads. This object holds all the necessary information for a file download request, such as the URL, HTTP method, headers, and more. ```APIDOC ## LinkDetails Constructor Creates a LinkDetails object for configuring remote file downloads. ### Parameters - **link** (String) - Required - The complete URL to download from (must include protocol http:// or https://). - **headers** (Map?) - Optional - HTTP request headers (e.g., Authorization, User-Agent). Not supported in downloadLink on web. - **body** (Object?) - Optional - Request body for POST requests. Can be a String, Map, FormData, or other Dio-compatible types. - **method** (String) - Optional - HTTP method: 'GET', 'POST', 'PUT', 'PATCH', 'DELETE', etc. Case-insensitive. Defaults to 'GET'. - **queryParameters** (Map?) - Optional - URL query parameters appended as ?key=value&... - **responseType** (ResponseType) - Optional - Dio ResponseType enum controlling how the response is decoded. Typically ResponseType.bytes for binary files. Defaults to ResponseType.bytes. ### Example ```dart final link = LinkDetails( link: 'https://api.example.com/v1/export', headers: {'Authorization': 'Bearer abc123'}, method: 'POST', body: {'format': 'pdf', 'id': 'doc-456'}, queryParameters: {'version': '2'}, ); ``` ``` -------------------------------- ### Get MimeType by Name Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/types.md Looks up a MimeType enum case by its human-readable name. Returns null if no match is found. ```dart static MimeType? get(String? name) ``` ```dart final mime = MimeType.get('PDF'); if (mime != null) { print(mime.type); // Output: application/pdf } ``` -------------------------------- ### Unsupported downloadLink Request Type Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/errors.md downloadLink() only supports simple GET requests. For POST or other complex requests, use saveLinkAsStream(). ```dart // ❌ This will throw (POST with body) await FileSaver.instance.downloadLink( link: LinkDetails( link: 'https://api.example.com/export', method: 'POST', body: {'format': 'pdf'}, ), ); // ✅ Use saveLinkAsStream instead await FileSaver.instance.saveLinkAsStream( name: 'export', link: LinkDetails( link: 'https://api.example.com/export', method: 'POST', body: {'format': 'pdf'}, ), fileExtension: 'pdf', mimeType: MimeType.pdf, ); ``` -------------------------------- ### LinkDetails with Basic Link Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/LinkDetails.md Shows how to create a LinkDetails object with only the required 'link' parameter. ```dart final details = LinkDetails(link: 'https://example.com/file.pdf'); print(details.link); // Output: https://example.com/file.pdf ``` -------------------------------- ### Get Source Path and Extension in saveAs() Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/Helpers.md Determines the source path for streaming and formats the file extension in the saveAs method. ```dart // Get source path for streaming final sourcePath = filePath ?? file_ops.filePathFromObject(file); // Same extension formatting String extension = includeExtension ? Helpers.getExtension(fileExtension: fileExtension) : ''; ``` -------------------------------- ### File Download with POST Request, Body, and Query Parameters Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/LinkDetails.md Initiates a file download via a POST request, including a JSON body and URL query parameters. Configure method, headers, body, and queryParameters in LinkDetails. ```dart final linkDetails = LinkDetails( link: 'https://api.example.com/generate', method: 'POST', headers: {'Content-Type': 'application/json'}, body: {'template': 'invoice', 'format': 'pdf'}, queryParameters: {'v': '2', 'async': 'false'}, ); await FileSaver.instance.saveFile( name: 'generated_invoice', link: linkDetails, fileExtension: 'pdf', mimeType: MimeType.pdf, ); ``` -------------------------------- ### Flutter Tool Backend Integration Source: https://github.com/incrediblezayed/file_saver/blob/main/example/windows/flutter/CMakeLists.txt Sets up a custom command to run the Flutter tool backend, ensuring it executes every time by using a phony output file. This command generates necessary Flutter library files and headers. ```cmake # === Flutter tool backend === # _phony_ is a non-existent file to force this command to run every time, # since currently there's no way to get a full input/output list from the # flutter tool. set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) add_custom_command( OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ${CPP_WRAPPER_SOURCES_APP} ${PHONY_OUTPUT} COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" ${FLUTTER_TARGET_PLATFORM} $ VERBATIM ) add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ${CPP_WRAPPER_SOURCES_APP} ) ``` -------------------------------- ### LinkDetails Configuration Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/README.md Configure URL-based downloads with LinkDetails. Specify the link, HTTP method, headers, body, and query parameters. ```dart LinkDetails( link: 'https://api.example.com/export', method: 'POST', headers: {'Authorization': 'Bearer token'}, body: {'format': 'pdf'}, queryParameters: {'version': '2'}, ) ``` -------------------------------- ### Compile Definitions and Include Directories Source: https://github.com/incrediblezayed/file_saver/blob/main/linux/CMakeLists.txt Configures compile-time definitions and interface include directories for the plugin library. ```cmake target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL) target_include_directories(${PLUGIN_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include" ) ``` -------------------------------- ### Simple File Download with LinkDetails Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/LinkDetails.md Saves a file from a given URL using default settings. Ensure the 'link' property is correctly set. ```dart final linkDetails = LinkDetails( link: 'https://example.com/document.pdf', ); await FileSaver.instance.saveFile( name: 'document', link: linkDetails, fileExtension: 'pdf', mimeType: MimeType.pdf, ); ``` -------------------------------- ### Save Methods Overview Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/INDEX.md Outlines the primary methods for saving files: `saveFile()` for default locations and `saveAs()` for user-selected locations. ```plaintext saveFile() → Default location, no dialog saveAs() → User picks location (where supported) ``` -------------------------------- ### Internal: Get Bytes from File Object Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/Helpers.md Internal helper method to extract bytes from a dart:io File object. Uses the 'file_ops.readFileBytes()' abstraction. ```dart static Future _getBytesFromFile(Object file) ``` -------------------------------- ### LinkDetails with Custom Headers Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/LinkDetails.md Demonstrates setting custom HTTP headers for a request, such as Authorization and User-Agent. ```dart final details = LinkDetails( link: 'https://api.example.com/protected', headers: { 'Authorization': 'Bearer token-123', 'User-Agent': 'MyApp/1.0', }, ); ``` -------------------------------- ### Internal: Get Bytes from File Path Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/Helpers.md Internal helper method to read file bytes directly from a file path string. Uses the 'file_ops.readPathBytes()' abstraction. ```dart static Future _getBytesFromPath(String path) ``` -------------------------------- ### Custom HTTP Client Configuration Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/architecture.md Shows how to pass a configured Dio instance to FileSaver for custom network settings like timeouts. ```dart final dio = Dio(BaseOptions(connectTimeout: Duration(seconds: 60))); await FileSaver.instance.saveFile( /* ... */ dioClient: dio, ); ``` -------------------------------- ### Flutter and System Dependencies Source: https://github.com/incrediblezayed/file_saver/blob/main/example/linux/CMakeLists.txt Includes Flutter managed directory, finds PkgConfig, and checks for GTK+ 3.0. ```cmake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") # Flutter library and tool build rules. add_subdirectory(${FLUTTER_MANAGED_DIR}) # System-level dependencies. find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") ``` -------------------------------- ### Get Bytes in saveFile() Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/Helpers.md Retrieves file bytes within the saveFile method, supporting file, filePath, or link inputs. It also handles formatting the file extension. ```dart // When getBytes needs to retrieve from file/link/bytes bytes = bytes ?? await Helpers.getBytes( file: file, filePath: filePath, link: link, dioClient: dioClient, transformDioResponse: transformDioResponse, ); // Format extension String extension = includeExtension ? Helpers.getExtension(fileExtension: fileExtension) : ''; ``` -------------------------------- ### LinkDetails with Query Parameters Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/LinkDetails.md Shows how to append query parameters to the URL for a request. ```dart final details = LinkDetails( link: 'https://api.example.com/search', queryParameters: { 'q': 'flutter', 'limit': 50, 'offset': 0, }, ); // Effective URL: https://api.example.com/search?q=flutter&limit=50&offset=0 ``` -------------------------------- ### Save File Using User Selection Dialog Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/README.md Opens a 'Save As' dialog on desktop or a file picker on mobile, allowing the user to choose the save location and filename. Returns the path or null if cancelled. ```dart // Open "Save As" dialog (desktop) or file picker (mobile) final path = await FileSaver.instance.saveAs( name: 'export_2024', bytes: reportBytes, fileExtension: 'pdf', mimeType: MimeType.pdf, ); if (path != null) { print('Saved to: $path'); } ``` -------------------------------- ### Get File Path Separator Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/Helpers.md Returns the platform-specific file path separator, always as a forward slash ('/'). Dart's File API accepts forward slashes on all platforms. ```dart static String getFilePathSlash() ``` -------------------------------- ### Handling StateError for Unavailable Downloads Directory Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/errors.md To handle the StateError when the downloads directory is unavailable, wrap the saveFile operation in a try-catch block. This allows you to gracefully manage the error, for example, by informing the user. ```dart try { await FileSaver.instance.saveFile( name: 'document', bytes: bytes, fileExtension: 'pdf', mimeType: MimeType.pdf, ); } on StateError catch (e) { print('Failed to save: ${e.message}'); // Handle storage unavailability } ``` -------------------------------- ### FileModel Constructor Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/FileModel.md Creates a FileModel instance with all required metadata for a file to be saved. Parameters include name, bytes, fileExtension, mimeType, and includeExtension. An optional sourcePath can be provided for native streaming. ```dart FileModel({ required String name, required Uint8List bytes, required String fileExtension, required String mimeType, required bool includeExtension, String? sourcePath, }) ``` ```dart final model = FileModel( name: 'report', bytes: Uint8List.fromList([/* PDF bytes */]), fileExtension: '.pdf', mimeType: 'application/pdf', includeExtension: true, ); ``` -------------------------------- ### File Organization Structure Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/INDEX.md Illustrates the directory structure of the file_saver plugin, showing the location of various documentation and source files. ```plaintext /workspace/home/output/ ├── INDEX.md (this file) ├── README.md (quick start & overview) ├── types.md (MimeType, FileModel definitions) ├── configuration.md (platform setup, permissions) ├── errors.md (exception handling) ├── architecture.md (system design & data flow) └── api-reference/ ├── FileSaver.md (main class) ├── LinkDetails.md (URL configuration) ├── FileModel.md (internal model) ├── FileSaverWeb.md (web implementation) ├── PlatformHandler.md (platform abstraction) └── Helpers.md (utility functions) ``` -------------------------------- ### Applying Standard Settings Source: https://github.com/incrediblezayed/file_saver/blob/main/example/windows/runner/CMakeLists.txt Applies standard build settings to the specified target. This is a custom macro or function defined elsewhere in the build system. ```cmake apply_standard_settings(${BINARY_NAME}) ``` -------------------------------- ### PlatformHandler Conditional Imports Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/PlatformHandler.md This snippet demonstrates how Dart's conditional imports are used to select the correct PlatformHandler implementation based on the target platform (web or native IO). It shows the setup for the abstract PlatformHandler class. ```dart import 'package:file_saver/src/platform_handler/platform_handler_stub.dart' if (dart.library.js_interop) 'package:file_saver/src/platform_handler/platform_handler_web.dart' if (dart.library.io) 'package:file_saver/src/platform_handler/platform_handler_all.dart'; abstract class PlatformHandler { static PlatformHandler get instance { return getPlatformHandler(); } // ... abstract methods } ``` -------------------------------- ### downloadLink Source: https://github.com/incrediblezayed/file_saver/blob/main/README.md Initiates a browser/system download for a file directly from a URL. This is suitable for large files where the app should not fetch the entire content into memory. ```APIDOC ## downloadLink ### Description Initiates a browser/system download for a file directly from a URL. This is suitable for large files where the app should not fetch the entire content into memory. On Web, this method cannot attach custom headers and relies on browser-managed cookies. On Android, it uses DownloadManager and can pass request headers. ### Method `downloadLink` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **link** (LinkDetails) - Required - Provides the URL, headers, request method, and body for the file download. - **name** (string) - Required - The desired name for the downloaded file. ### Request Example ```dart await FileSaver.instance.downloadLink( link: LinkDetails(link: "https://example.com/large-file.zip"), name: "large-file.zip", ); ``` ### Response #### Success Response Indicates the download has been initiated. #### Response Example None provided. ``` -------------------------------- ### Get File Bytes from Various Sources Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/Helpers.md Retrieves file bytes from a file path, a remote link, or a File object. Supports custom Dio clients and response transformations. At least one source parameter must be provided. ```dart static Future getBytes({ String? filePath, LinkDetails? link, Object? file, Dio? dioClient, Uint8List Function(dynamic data)? transformDioResponse, }) ``` -------------------------------- ### downloadFile Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/FileSaverWeb.md Saves a file directly to the user's download directory. Suitable for small files (under 50MB) and supported by all browsers. ```APIDOC ## downloadFile ### Description Saves a file directly to the user's download directory. Suitable for small files (under 50MB) and supported by all browsers. ### Method ```dart FileSaver.instance.saveFile ``` ### Parameters #### Named Parameters - **name** (string) - Required - The base name for the downloaded file. - **bytes** (Uint8List) - Required - The file content as a byte list. - **fileExtension** (string) - Required - The extension for the file (e.g., 'pdf'). - **mimeType** (MimeType) - Required - The MIME type of the file (e.g., MimeType.pdf). ### Request Example ```dart await FileSaver.instance.saveFile( name: 'document', bytes: fileBytes, fileExtension: 'pdf', mimeType: MimeType.pdf, ); ``` ``` -------------------------------- ### downloadLink() - Platform-Specific Flow Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/architecture.md Details the execution flow for downloading a link, highlighting platform-specific handling for web and Android. ```dart FileSaver.downloadLink({ link, name }) │ ├─ Validate: GET only, no headers/body on web │ └─ PlatformHandler.downloadLink(link) │ ├─ Web: │ └─ FileSaverWeb.downloadLink(url) │ └─ HTMLAnchorElement.click() │ └─ Android: └─ MethodChannel → Java DownloadManager ``` -------------------------------- ### iOS Info.plist Configuration Source: https://github.com/incrediblezayed/file_saver/wiki/Home These keys should be added to your iOS project's info.plist file to enable file sharing and in-place document opening, making saved files visible in the iOS Files application. ```xml LSSupportsOpeningDocumentsInPlace UIFileSharingEnabled ``` -------------------------------- ### Download File in Browser Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/FileSaverWeb.md Use this method to download a file by creating a Blob and triggering a browser download. It's suitable for files up to around 100MB. The entire file is loaded into browser memory. ```dart final fileModel = FileModel( name: 'document.pdf', bytes: pdfBytes, fileExtension: '.pdf', mimeType: 'application/pdf', includeExtension: true, ); try { final success = await FileSaverWeb.downloadFile(fileModel); print(success); // true } catch (e) { print('Download failed: $e'); } ``` -------------------------------- ### Conditional Platform Behavior for File Saving Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/README.md Demonstrates how to implement conditional logic for saving files based on whether the application is running on the web or a native platform. Handles different saving strategies for large files on the web versus native streams. ```dart import 'package:flutter/foundation.dart'; if (kIsWeb) { // Web-specific code if (isLargeFile) { await FileSaver.instance.downloadLink( link: LinkDetails(link: url), name: 'file.zip', ); } else { await FileSaver.instance.saveFile( name: 'file', link: LinkDetails(link: url), fileExtension: 'zip', mimeType: MimeType.zip, ); } } else { // Native platform await FileSaver.instance.saveAsStream( name: 'file', stream: largeStream, fileExtension: 'zip', mimeType: MimeType.zip, ); } ``` -------------------------------- ### File Download with Authentication Headers Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/LinkDetails.md Downloads a file from a URL that requires authentication. Include necessary headers in the LinkDetails object. ```dart final linkDetails = LinkDetails( link: 'https://api.example.com/exports/report.xlsx', headers: {'Authorization': 'Bearer xyz789'}, ); await FileSaver.instance.saveFile( name: 'monthly_report', link: linkDetails, fileExtension: 'xlsx', mimeType: MimeType.microsoftExcel, ); ``` -------------------------------- ### LinkDetails with POST Request Body Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/LinkDetails.md Illustrates creating a LinkDetails object for a POST request, including a request body. ```dart final details = LinkDetails( link: 'https://api.example.com/upload', method: 'POST', body: {'file_name': 'myfile.pdf', 'size': 1024}, ); ``` -------------------------------- ### macOS Entitlements for File Access Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/configuration.md Configure macOS entitlements in DebugProfile.entitlements and Release.entitlements to allow read-write access to the Downloads folder and network client access. ```xml com.apple.security.files.downloads.read-write com.apple.security.network.client ``` -------------------------------- ### Apply Standard Compilation Settings Source: https://github.com/incrediblezayed/file_saver/blob/main/example/linux/CMakeLists.txt Applies C++14 standard, warning flags, optimization, and NDEBUG definition based on build type. ```cmake function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_14) target_compile_options(${TARGET} PRIVATE -Wall -Werror) target_compile_options(${TARGET} PRIVATE "$<$>:-O3>") target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>") endfunction() ``` -------------------------------- ### Bundled Libraries Configuration Source: https://github.com/incrediblezayed/file_saver/blob/main/linux/CMakeLists.txt Defines a list of absolute paths to libraries that should be bundled with the plugin. Currently set to an empty list. ```cmake set(file_saver_bundled_libraries "" PARENT_SCOPE ) ``` -------------------------------- ### Mock Dio Response for Testing Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/Helpers.md Demonstrates how to mock a Dio response for testing purposes, allowing simulation of HTTP requests and responses for the _getBytesFromLink method. ```dart // Example: Mock a Dio response for testing final mockDio = MockDio(); mockDio.onGet('https://example.com/file.pdf').reply(200, pdfBytes); await FileSaver.instance.saveFile( name: 'document', link: LinkDetails(link: 'https://example.com/file.pdf'), fileExtension: 'pdf', mimeType: MimeType.pdf, dioClient: mockDio, ); ``` -------------------------------- ### macOS Entitlements Configuration Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/README.md Add entitlements to DebugProfile.entitlements for network client and file download access on macOS. ```xml com.apple.security.files.downloads.read-write com.apple.security.network.client ``` -------------------------------- ### MethodChannel Initialization Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/PlatformHandler.md Initializes the MethodChannel for communication with native platform code. The channel name is 'file_saver'. ```dart final MethodChannel _channel = const MethodChannel('file_saver'); ``` -------------------------------- ### Save As (Platform Dispatcher) Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/PlatformHandler.md Opens a file picker dialog. Handles platform-specific MethodChannel invocations or throws an UnimplementedError for unsupported platforms like Linux. ```dart @override Future saveAs(FileModel fileModel) async { String? path; if (Platform.isAndroid || Platform.isIOS || Platform.isMacOS) { path = await _channel.invokeMethod(_saveAs, fileModel.toMap()); } else if (Platform.isWindows) { final Int64List? bytes = await _channel.invokeMethod( 'saveAs', fileModel.toMap(), ); path = bytes == null ? null : String.fromCharCodes(bytes); } else { throw UnimplementedError('Unimplemented Error'); } return path; } ``` -------------------------------- ### saveLinkAsStream() - Native Implementation Flow Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/architecture.md Illustrates the native execution flow for saving a link as a stream, involving network requests, temporary file creation, and final saving. ```dart FileSaver.saveLinkAsStream({ name, link, fileExtension, ... }) │ └─ !kIsWeb → True │ ├─ Dio.request(link.link) → ResponseBody.stream │ ├─ writeStreamToTempFile(stream) │ └─ Creates temp file with stream data │ └─ saveAs(filePath: tempFile) → final save location │ └─ deleteFile(tempFile) → cleanup ``` -------------------------------- ### MimeType Enum Usage Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/README.md Demonstrates how to use the MimeType enum to specify file types, including pre-defined formats and the option for custom types. Shows how to retrieve a MIME type by its name. ```dart MimeType.pdf // application/pdf MimeType.custom // '' (requires customMimeType parameter) // Look up by name final mime = MimeType.get('PDF'); ``` -------------------------------- ### Generated Plugin Integration Source: https://github.com/incrediblezayed/file_saver/blob/main/example/linux/CMakeLists.txt Includes the CMake script for integrating generated plugins. ```cmake # Generated plugin build rules, which manage building the plugins and adding # them to the application. include(flutter/generated_plugins.cmake) ``` -------------------------------- ### FileModel Map Conversion for Platform Channels Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/FileModel.md Shows how the toMap method is used internally by the plugin to communicate FileModel data with native code via platform channels. ```dart // The plugin uses toMap internally when communicating with platform channels final model = FileModel( name: 'document', bytes: Uint8List.fromList([/* data */]), fileExtension: '.pdf', mimeType: 'application/pdf', includeExtension: true, ); final mapData = model.toMap(); // This is used by the MethodChannel to communicate with native code final result = await channel.invokeMethod('saveFile', mapData); ``` -------------------------------- ### Configure Custom Dio HTTP Client Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/configuration.md Configure a custom Dio client with specific options like timeouts and headers. This custom client can then be passed to the saveFile method for network requests. ```dart // Create a custom Dio client with your configuration final dio = Dio( BaseOptions( connectTimeout: Duration(seconds: 30), receiveTimeout: Duration(seconds: 30), headers: { 'User-Agent': 'MyApp/1.0', 'Accept': '*/*', }, ), ); // Use it with file_saver await FileSaver.instance.saveFile( name: 'document', link: LinkDetails( link: 'https://api.example.com/file', headers: {'Authorization': 'Bearer token'}, ), fileExtension: 'pdf', mimeType: MimeType.pdf, dioClient: dio, ); ``` -------------------------------- ### downloadLink Source: https://github.com/incrediblezayed/file_saver/blob/main/_autodocs/api-reference/PlatformHandler.md Hands off a URL to the system download manager without loading the file into Dart memory. Returns 'Downloads' on success, null on failure. ```APIDOC ## downloadLink ### Description Hands off a URL to the system download manager without loading the file into Dart memory. ### Method Abstract method ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **link** (LinkDetails) - Required - URL and request details - **name** (String?) - Optional - Suggested filename ### Request Example ```json { "link": { "url": "http://example.com/file.zip", "headers": {"Authorization": "Bearer token"} }, "name": "archive.zip" } ``` ### Response #### Success Response (200) - **String?** - Returns 'Downloads' on success, null on failure. #### Response Example ```json "Downloads" ``` ```