Skip to content
pubscout

cross_file

0.4.0, released 8 weeks ago by flutter.dev

An abstraction to allow working with files across multiple platforms.

WASM-ready
$ flutter pub add cross_file
Source repository

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.

  • file

    A pluggable file system abstraction for Dart that matches dart:io APIs.

Works with

Packages commonly used together with cross_file: ones it builds on, ones built on it, and its own family.