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.
Useful Links​
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.dartexposes the generatedcodegenVersion.rust/src/frb_generated.rsexposesFLUTTER_RUST_BRIDGE_CODEGEN_VERSION.pubspec.yamlpins the Dartflutter_rust_bridgeruntime.rust/Cargo.tomlpins the Rustflutter_rust_bridgeruntime.
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:
- Install and run the matching
flutter_rust_bridge_codegenversion. - Update
flutter_rust_bridgein bothpubspec.yamlandrust/Cargo.toml. - Regenerate the bindings with
flutter_rust_bridge_codegen generate. - Build the Rust library with
cargo build -r. - Run
dart testfrombindings/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.