dart_cpp_bridge
Dart/Flutter ↔ C++20 binding generator, inspired by flutter_rust_bridge.
Write normal C++ code and call it from Dart/Flutter, with sync, async, stream, and Dart-closure reverse calls.
What's this?
- Write plain C++20 functions and classes — no hand-written FFI boilerplate
- Codegen generates Dart API + C++ wire dispatch from annotated headers
- Built-in runtime based on Asio + async-simple coroutines
- Supports Android, iOS, Windows, Linux, and macOS
Quickstart
See the documentation for a complete quickstart:
- English: deretame.github.io/dart_cpp_bridge/getting-started/
- 中文: deretame.github.io/dart_cpp_bridge/zh-cn/getting-started/
Show me the code
C++
#include <dart_cpp_bridge/annotate.h>
BRIDGE_SYNC int32_t add(int32_t a, int32_t b) { return a + b; }
BRIDGE_ASYNC
async_simple::coro::Lazy<std::string> greet(std::string name) {
co_return "Hello, " + name;
}
Dart
import 'package:my_app/src/native_gen/api/api_fn.dart';
void main() async {
await DcbLib.init();
print(add(a: 1, b: 2)); // 3
print(await greet(name: 'World')); // Hello, World
}
Documentation
- Homepage: deretame.github.io/dart_cpp_bridge/
- Quickstart: deretame.github.io/dart_cpp_bridge/getting-started/
- GitHub: github.com/deretame/dart_cpp_bridge
Acknowledgments
- Flutter Rust Bridge — architecture and product shape inspiration
- Asio — event loop and asynchronous I/O
- async-simple — C++20 coroutine runtime
- concurrentqueue — lock-free concurrent queue
- Dart / Flutter team — FFI, Isolate, NativeFinalizer, and the broader Dart native ecosystem
License
MIT — see LICENSE.
Libraries
- dart_cpp_bridge
- Dart FFI front-end for the dart_cpp_bridge C++ runtime.
- hook
- Build-hook support for dart_cpp_bridge Native Assets.