Skip to main content

Dart 🚧

Apache OpenDALâ„¢ Dart Binding (WIP)

Note: This binding has its own independent version number, which may differ from the Rust core version. When checking for updates or compatibility, always refer to this binding's version rather than the core version.

Usage​

Api is designed to be like stdlib style.

This is stdlib

import 'dart:io';

void main() async {
final file = File('file.txt');
var is_exists = await file.exists();
print(is_exists);
}

This is opendal

import 'package:opendal/opendal.dart';

void main() async {
final storage = await Storage.init(schemeStr: "fs", map: {"root": "/tmp"});
final File = storage.initFile();
// drop-in
final file = File('file.txt');
var is_exists = await file.exists();
print(is_exists);
}

Test​

dart run tests/opendal_test.dart

Development​

dart pub get
flutter_rust_bridge_codegen generate
cd rust
cargo build -r
cd ..
dart test

For a cross-compiled build, pass the target explicitly:

cd rust
cargo build -r --target x86_64-unknown-linux-gnu # change to your arch, refer to https://doc.rust-lang.org/beta/rustc/platform-support.html

Storage.init loads the native library from the target-specific release directory when it exists, for example rust/target/aarch64-apple-darwin/release/ on macOS arm64. For native local builds, cargo build -r writes the library to rust/target/release/; the loader falls back to that directory automatically.

Update generated code​

This binding uses https://github.com/fzyzcjy/flutter_rust_bridge. The codegen version and both runtime dependencies must match exactly:

  • Generated Dart files record the codegen version in comments like @generated by flutter_rust_bridge @ <version>.
  • lib/src/rust/frb_generated.dart exposes the generated codegenVersion.
  • rust/src/frb_generated.rs exposes FLUTTER_RUST_BRIDGE_CODEGEN_VERSION.
  • pubspec.yaml pins the Dart flutter_rust_bridge runtime.
  • rust/Cargo.toml pins the Rust flutter_rust_bridge runtime.

If these versions drift apart, startup and tests can fail with a flutter_rust_bridge content-hash or version mismatch. When upgrading flutter_rust_bridge:

  1. Install and run the matching flutter_rust_bridge_codegen version.
  2. Update flutter_rust_bridge in both pubspec.yaml and rust/Cargo.toml.
  3. Regenerate the bindings with flutter_rust_bridge_codegen generate.
  4. Build the Rust library with cargo build -r.
  5. Run dart test from bindings/dart.

Generated APIs can be renamed by flutter_rust_bridge between versions. Keep the public Dart wrapper stable unless the PR intentionally makes a breaking API change. For example, the generated Operator constructor may use a parameter name such as scheme, while Storage.init(schemeStr: ...) can preserve the existing public parameter and pass it through internally.

License and Trademarks​

Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0

Apache OpenDAL, OpenDAL, and Apache are either registered trademarks or trademarks of the Apache Software Foundation.