cross_file
0.4.0, released 8 weeks ago by flutter.dev
An abstraction to allow working with files across multiple platforms.
WASM-ready
What it does
Provides a unified API for interacting with resources and files across multiple platforms using file systems and scoped storage abstractions. Offers support for Android, iOS, Web, Windows, macOS, and Linux.
AI-written summary of version 0.4.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need to write cross-platform code that interacts with files or directories on different operating systems.
- You are handling platform-specific storage patterns like Android content URIs or iOS security-scoped bookmarks.
Skip it when
- You only target a single platform with native file handling.
- You need high-level file picker UI components (use file_picker instead).
Strengths
- Unified file API across mobile, desktop, and web.
- Supports implementation-specific features via extensions and platform packages.
- Handles both traditional file systems and restricted platform storage.
Weaknesses
- Recent major version updates introduced breaking changes to instantiation and helper methods.
- Requires platform-specific packages to access advanced implementation details.
Setup
- Kind
- Plugin (native code)
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 5
Add platform implementation packages such as cross_file_io, cross_file_android, cross_file_darwin, or cross_file_web if platform-specific features are needed.
final file = XFile.fileSystem(path: 'assets/hello.txt');
debugPrint('File information:');
debugPrint('- URI: ${file.uri}');
debugPrint('- Name: ${await file.name()}');
if (await file.exists()) {
final String fileContent = await file.readAsString();
debugPrint('Content of the file: $fileContent');
}Alternatives
Packages that do the same job and could replace cross_file.
Works with
Packages commonly used together with cross_file: ones it builds on, ones built on it, and its own family.
- share_plusBuilt on cross_fileShare text, files, or URIs via native share dialogs on mobile, web, and desktop.
- file_pickerBuilt on cross_fileUse the native file explorer to pick single or multiple files, directories, and save files.
- file_selector_linuxBuilt on cross_fileLinux implementation of the file_selector plugin for picking and saving files.
- file_selector_macosBuilt on cross_filemacOS implementation of the file_selector plugin
- file_picker_webBuilt on cross_fileWeb implementation of file_picker for selecting, streaming, and saving files in browsers.
- file_picker_platform_interfaceBuilt on cross_fileCommon platform interface for the file_picker federated plugin.
- desktop_dropBuilt on cross_fileReceive dragged files, directories, text, and URLs into Flutter apps
- get_thumbnail_videoBuilt on cross_fileGenerates image thumbnails from local video files, URLs, or assets.