This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git
The following commit(s) were added to refs/heads/main by this push:
new a77843ca9 feat(binding/dart): add examples, tests (#5740)
a77843ca9 is described below
commit a77843ca9f5e94c53e8247117c2f9f3ccdd6a796
Author: Asuka Minato <[email protected]>
AuthorDate: Tue Mar 11 17:11:07 2025 +0900
feat(binding/dart): add examples, tests (#5740)
* add examples, tests
* re-export file
* typo
* add license header
* typo
---
.github/workflows/ci_bindings_dart.yml | 3 +-
bindings/dart/README.md | 48 ++++++++++++++++++++++++--
bindings/dart/examples/basic.dart | 26 ++++++++++++++
bindings/dart/lib/opendal.dart | 19 ++++++++++
bindings/dart/{lib => tests}/opendal_test.dart | 4 +--
5 files changed, 93 insertions(+), 7 deletions(-)
diff --git a/.github/workflows/ci_bindings_dart.yml
b/.github/workflows/ci_bindings_dart.yml
index a3b558618..f874d9dda 100644
--- a/.github/workflows/ci_bindings_dart.yml
+++ b/.github/workflows/ci_bindings_dart.yml
@@ -76,5 +76,4 @@ jobs:
- name: test
working-directory: bindings/dart
run: |
- dart run lib/opendal_test.dart
-
+ dart run tests/opendal_test.dart
diff --git a/bindings/dart/README.md b/bindings/dart/README.md
index 00a4be326..dd82802de 100644
--- a/bindings/dart/README.md
+++ b/bindings/dart/README.md
@@ -1,5 +1,47 @@
# Apache OpenDALâ„¢ Dart Binding (WIP)
+## Useful Links
+
+- [Examples](./examples)
+
+## 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 'opendal.dart';
+
+void main() async {
+ await RustLib.init();
+ final File = FileManager.initOp(schemeStr: "fs", map: {"root": "/tmp"});
+ // drop-in
+ final file = File('file.txt');
+ var is_exists = await file.exists();
+ print(is_exists);
+}
+
+```
+
+## Test
+
+```
+dart run tests/opendal_test.dart
+```
+
## Development
```
@@ -7,10 +49,12 @@ flutter pub get
flutter_rust_bridge_codegen generate
cd rust
cargo build -r
-cd ..
-dart run lib/opendal_test.dart
```
+## Update generated code
+
+This binding uses <https://github.com/fzyzcjy/flutter_rust_bridge>, when
updating the codegen. First check `FLUTTER_RUST_BRIDGE_CODEGEN_VERSION`, then
pin the version of `flutter_rust_bridge` in `pubspec.yaml` and
`rust/Cargo.toml`. Make sure the runtime versions are matched.
+
## License and Trademarks
Licensed under the Apache License, Version 2.0:
http://www.apache.org/licenses/LICENSE-2.0
diff --git a/bindings/dart/examples/basic.dart
b/bindings/dart/examples/basic.dart
new file mode 100644
index 000000000..9ab8a5dfb
--- /dev/null
+++ b/bindings/dart/examples/basic.dart
@@ -0,0 +1,26 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+import '../lib/opendal.dart';
+
+void main() async {
+ await RustLib.init();
+ final File = FileManager.initOp(schemeStr: "fs", map: {"root": "/tmp"});
+ // drop-in style
+ var testFile = File("test_1.txt");
+ assert(!(await testFile.exists()));
+}
diff --git a/bindings/dart/lib/opendal.dart b/bindings/dart/lib/opendal.dart
index 6ea4f691b..d7ceefa11 100644
--- a/bindings/dart/lib/opendal.dart
+++ b/bindings/dart/lib/opendal.dart
@@ -1,5 +1,24 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
import 'src/rust/frb_generated.dart';
import 'src/rust/api/opendal_api.dart';
+export 'src/rust/frb_generated.dart';
+export 'src/rust/api/opendal_api.dart';
class FileManager {
final Operator _operator;
diff --git a/bindings/dart/lib/opendal_test.dart
b/bindings/dart/tests/opendal_test.dart
similarity index 93%
rename from bindings/dart/lib/opendal_test.dart
rename to bindings/dart/tests/opendal_test.dart
index fcbe720a5..ee1c57063 100644
--- a/bindings/dart/lib/opendal_test.dart
+++ b/bindings/dart/tests/opendal_test.dart
@@ -1,7 +1,5 @@
import 'package:test/test.dart';
-import 'src/rust/frb_generated.dart';
-import 'src/rust/api/opendal_api.dart';
-import 'opendal.dart';
+import '../lib/opendal.dart';
void main() {
group('opendal unit test', () {