flutter_rust_bridge 2.0.0-dev.0 copy "flutter_rust_bridge: ^2.0.0-dev.0" to clipboard
flutter_rust_bridge: ^2.0.0-dev.0 copied to clipboard

High-level memory-safe binding generator for Flutter/Dart <-> Rust

flutter_rust_bridge #

Rust Package Flutter Package Stars CI codecov Codacy Badge

Logo

What's new in V2 #

Please visit this page for information and update guide.

🚧 V2 will still be WIP for few days #

Please use the old v1 https://cjycode.com/flutter_rust_bridge/v1/ currently.

The 2.0.0-dev.1 will contain bugs and missing features, because I have to have a real (pre-)release before I can start working on the last part of tests and functionalities. So it is a chicken-and-egg problem ;) But I expect 2.0.0-dev.2 (or -dev.3) to be stable.

πŸš€ Advantages #

  • Officially Flutter Favorite: This package is officially Flutter Favorite, and is in the first batch of 7 packages at its rebooting.
  • Seamless communication: Call Rust from Dart, as if calling the same language.
    • Arbitrary types: Use arbitrary Rust and Dart types, even if they are not serializable or non-clone.
    • Async & sync x Rust & Dart: Multi modes for various needs - Avoid blocking the main thread, or sync API (e.g. used in Widget.build); Async runtime for IO bound tasks, or thread pools for CPU-heavy computations.
    • Two-way road: Not only can Dart call Rust - Rust can also call Dart.
    • Auto-translatable types: Lots of types can be further translated to Dart native types, e.g. complex enums and structs, zero-copy big arrays, errors (Result), and Streams (iterator).
    • Safety: Focus on your code, and forget memory safety, malloc/free, or undefined behavior completely.
    • Other features: Support whole folders as input, and the output folder will preserve hierarchy. Methods (not only functions).
  • Quick setup, but fully customizable: Run a one-liner command, then get a ready-to-use project (or integrate into existing projects). Provide sensible defaults, but everything can be customized.
  • Solid CI: We have CI for Valgrind, sanitizers (ASAN/MSAN/LSAN), testing for each platform, benchmarking, codecov, etc.
  • Fast: It is only a thin (though feature-rich) wrapper, benchmarked on CI, and even has multiple codecs for best performance under different workloads.
  • Lightweight: You are free to use your favorite Flutter and Rust libraries and toolchains (e.g. runner, debugger).
  • Cross-platform: Android, iOS, Windows, Linux, MacOS, and Web.
  • Pure-Dart compatible: Despite the name, this package is 100% compatible with pure Dart.

Why Flutter + Rust? #

Click to expand

Firstly, super briefly introduce each component (you can find much more in a lot of blogs and posts):

  • Flutter: Cross-platform, hot-reload, rapid-development, flexible UI toolkit.
    • "The most popular cross-platform mobile SDK" (by StackOverflow [1][2]).
  • Rust: Highly efficient and performant, reliable, productive.
    • "The most desired programming language" for 8 years (by StackOverflow and GitHub [1][2]).

Typical scenarios to combine them include:

  • UI framework for Rust: When you want a UI framework for your Rust system.
  • Use arbitrary Rust libraries in Flutter: When the desired functionality only has a library in Rust, not Dart (Flutter).
  • Need high-performance code for Flutter: Rust makes it easy and performant to write multi-thread code, algorithms, data-intensive operations, etc.
  • ...

🧭 Show me the code #

show-me-the-code

πŸ’‘ Documentation #

Check out the documentation for quickstart, full guides and more.

✨ Acknowledgments and contributors #

Firstly, I want to sincerely thank Dart, Flutter and Rust (alphabetical order). Dart provides a solid foundation for productive UI development, Flutter enables developers to make cross-platform apps with ease, and Rust empowers everyone to build reliable and efficient software. Without the languages and frameworks, this bridge connects absolutely nothing. Besides, I also want to express my thanks for conferring the official Flutter Favorite honor to the package. In addition, I also want to say thanks to the Dart, Flutter and Rust team members as well as community members, who have helped me during the development of flutter_rust_bridge by valuable discussions, insights, and actions.

Secondly, thanks goes to these wonderful contributors (emoji key following all-contributors specification):

All Contributors

fzyzcjy
fzyzcjy

πŸ’» πŸ“– πŸ’‘ πŸ€” 🚧
Viet Dinh
Viet Dinh

πŸ’» ⚠️ πŸ“–
rogurotus
rogurotus

πŸ’» πŸ“–
Nicolas Gasull
Nicolas Gasull

πŸ’»
Joshua Wade
Joshua Wade

πŸ’»
Lattice 0
Lattice 0

πŸ’» πŸ“–
Unoqwy
Unoqwy

πŸ’»
Anton Lazarev
Anton Lazarev

πŸ’»
sagu
sagu

πŸ’» πŸ“–
Sebastian Urban
Sebastian Urban

πŸ’»
Rom's
Rom's

πŸ’» πŸ“–
老董
老董

πŸ’» πŸ“–
Gregory Conrad
Gregory Conrad

πŸ“– πŸ’»
huang12zheng
huang12zheng

πŸ’» πŸ“–
Daniel
Daniel

πŸ’»
Manuel Philipp
Manuel Philipp

πŸ’» πŸ“–
SoLongAnd...
SoLongAnd...

πŸ’» πŸ“–
hsfzxjy
hsfzxjy

πŸ’»
Cupnfish
Cupnfish

πŸ’»
alanlzhang
alanlzhang

πŸ’» πŸ“–
Erikas Taroza
Erikas Taroza

πŸ’»
菘菘
菘菘

πŸ’»
SimplyKyle!
SimplyKyle!

πŸ’»
Zaitam
Zaitam

πŸ’»
Brent Lewis
Brent Lewis

πŸ’» πŸ“–
nitn3lav
nitn3lav

πŸ’» πŸ“–
Alex Procelewski
Alex Procelewski

πŸ“– πŸ’»
Kevin Li
Kevin Li

πŸ’» πŸ“–
Daniel Porteous (dport)
Daniel Porteous (dport)

πŸ“–
Andreas Monitzer
Andreas Monitzer

πŸ’»
Kim Dong-Hyun
Kim Dong-Hyun

πŸ’» πŸ“–
NightFeather
NightFeather

πŸ’»
九月
九月

πŸ’»
Wouter Ensink
Wouter Ensink

πŸ“–
Marcel
Marcel

πŸ’»
Aidan
Aidan

πŸ“–
Patrick Auernig
Patrick Auernig

πŸ’»
Sai Chaitanya
Sai Chaitanya

πŸ’»
Xidorn Quan
Xidorn Quan

πŸ’»
jsonmona
jsonmona

πŸ’»
codercengiz
codercengiz

πŸ’»
Michael Bryan
Michael Bryan

πŸ’»
Philip Kannegaard Hayes
Philip Kannegaard Hayes

πŸ’»
bus710
bus710

πŸ“–
._.
._.

πŸ“–
Marc Gutenberger
Marc Gutenberger

πŸ’»
Andrii Stadnik
Andrii Stadnik

πŸ’»
Aran Donohue
Aran Donohue

πŸ’»
syndim
syndim

πŸ’»
Ares Andrew
Ares Andrew

πŸ“–
polypixeldev
polypixeldev

πŸ“–
CicadaCinema
CicadaCinema

πŸ’» πŸ“–
Fabian LΓΆschner
Fabian LΓΆschner

πŸ’»
Vincent Herlemont
Vincent Herlemont

πŸ’»
Roman Zaynetdinov
Roman Zaynetdinov

πŸ“–
raphaelrobert
raphaelrobert

πŸ“–
Mouayad Alhamwi
Mouayad Alhamwi

πŸ“–
elliotsayes
elliotsayes

πŸ“–
muji
muji

πŸ“–
thomas725
thomas725

πŸ“–
orange soeur
orange soeur

πŸ“–
Alex Gorichev
Alex Gorichev

πŸ“–
Sven-Hendrik Haase
Sven-Hendrik Haase

πŸ“–
Chris Ohk
Chris Ohk

πŸ“–
Vitalii Hurianov
Vitalii Hurianov

πŸ“–
Sam Nystrom
Sam Nystrom

πŸ“–
max
max

πŸ“–
Jonathan
Jonathan

πŸ“–
Akash Jaiswal
Akash Jaiswal

πŸ“–
Febrian Setianto
Febrian Setianto

πŸ“–
Satvik Pendem
Satvik Pendem

πŸ’»
rustui
rustui

πŸ“–
J
J

πŸ“–
Ikko Ashimine
Ikko Ashimine

πŸ“–
thesimplekid
thesimplekid

πŸ“–

More specifically, thanks for all these contributions:

  • Desdaemon: Support not only simple enums but also enums with fields which gets translated to native enum or sealed freezed class in Dart. Support the Option type as nullable types in Dart. Support Vec of Strings type. Support tuple type. Support comments in code. Add marker attributes for future usage. Add Linux and Windows support for with-flutter example, and make CI works for that. Avoid parameter collision. Overhaul the documentation and add several chapters to demonstrate configuring a Flutter+Rust project in all five platforms. Refactor command module. Precompiled binary CI workflow. Fix bugs. Add support for the Web platform, parallel to the existing mobile/desktop platforms, via WASM and JavaScript as intermediate values. GitHub retry actions. Implement draft of opaque types. Refactor Boxed and Option. Impl list of dates and optionals. Parameter defaults. Refactor CLI. Refactor codegen errors.
  • rogurotus: Add Rust opaque types, enabling arbitrary Rust structs to be used as opaque Dart objects by generating wrappers and raw Arc pointers. Also add Dart opaque types, allowing to use any Dart objects in Rust code. Extend SyncReturn for more types. Fix generation bug. Fix SyncReturn. Migrate to dart-sys. Update CI. Fix linters. Fix SyncReturn bug.
  • ngasull: Make sync mode support whatever types that classical async mode supports. Bump sdk.
  • SecondFlight: Allow structs and enums to be imported from other files within the crate by creating source graph. Auto-create relevant dir. Fix store_dart_post_cobject error with ffigen 6.0.
  • lattice0: Implement hierarchy of exceptions. Support methods, such that Rust struct impls can be converted to Dart class methods. StreamSink at any argument.
  • Unoqwy: Add struct mirrors, such that types in the external crates can be imported and used without redefining and copying.
  • antonok-edm: Avoid converting syn types to strings before parsing to improve code and be more robust.
  • sagudev: Make code generator a lib. Add error types. Depend on cbindgen. Fix LLVM paths. Update deps. Fix CI errors.
  • surban: Support unit return type. Skip unresolvable modules. Ignore prefer_const_constructors. Non-final Dart fields.
  • Roms1383: Fix build_runner calling bug. Remove global ffigen dependency. Improve version check. Fix enum name-variant conflicts. Support Chrono date time and UUID types. Migrate to Rust 1.64 workspace. Update and refactor CI. Update header comments. Code cleanup.
  • dbsxdbsx: Allow generating multiple Rust and Dart files. Fix lint. Update doc. Add logging.
  • GregoryConrad: Add doc to setup frb inside a Dart/Flutter library.
  • huang12zheng: Support type aliases and nested ones. Tweak code generation. Fix rust_build_and_test on Mac. Improve CI logic and cache. Remove bridge field in model.
  • trobanga: Add support for [T;N] structs. Add usize support. Add a cmd argument. Separate dart tests. Fix fallible list case.
  • MnlPhlp: Support macros and will auto expand. Allow mirror types in streams.
  • SoLongAndThanksForAllThePizza: Refactor and enhance SyncReturn to support more types. Refactor post-release CI.
  • hsfzxjy: Fix SyncReturn use-after-free bug.
  • Cupnfish: Support arrays as function parameters. Allow multi mirror.
  • alanlzhang: Add generation for Dart metadata. Enhance module parser. Fix enum in struct. Fix linter.
  • erikas-taroza: Support list of primitive enums. Make enum camelCase. Warn wrong path. Fix cargo expand.
  • SiongSng: Finish implementing exception hierarchy. Fix SyncReturn bug.
  • JustSimplyKyle: Also finish implementing exception hierarchy.
  • Zaitam: Fix when method return struct. Partial migration to Dart 3.
  • coder0xff: Discuss binding unmodified Rust. Refactor SupportedInnerType. Extra codegen tester.
  • nitn3lav: Nested structs without Box.
  • alexthe2: Add Option Datetime. Add empty structs. Improve doc. Add r#. Fix mirror enum bug.
  • AlienKevin: Add flutter example for macOS. Add doc for Android NDK bug.
  • banool: Fix pubspec parsing. Fix symbol-stripping doc.
  • anlumo: Fix freezed + methods. Non-clone RustOpaque.
  • temeddix: Fix broken CI. Custom num workers. Fix MacOS doc steps. Update doc. Make zero-copy defaultable.
  • NightFeather0615: Fix Vec bool.
  • OfficialBoyfriend: Fix error display.
  • w-ensink: Improve doc. Fix CI. Refactor. Add tests.
  • smw-wagnerma: Improve Windows encoding handling.
  • powpingdone: Document JNI init and libc++_static linking.
  • valeth: Rename callFfi's port.
  • sccheruku: Prevent double-generating utility.
  • upsuper: Refactor delegate-attr.
  • jsonmona: Add import.
  • codercengiz: Fix mirroring bug.
  • Michael-F-Bryan: Detect broken bindings.
  • phlip9: Fix no-serde compilation.
  • bus710: Add a case in troubleshooting.
  • Demezy: Mention troubleshooting.
  • gutenfries: Bump proc-macros.
  • anstadnik: Check keywords.
  • aran: Fix pubspec. Bump version.
  • syndim: Add a bracket to box.
  • TENX-S: Improve doc. Reproduce a bug.
  • polypixeldev: Improve doc.
  • CicadaCinema: Bump version. Improve doc.
  • w1th0utnam3: Improve message.
  • vincent-herlemont: Loosen version.
  • zaynetro: Improve doc.
  • raphaelrobert: Remove oudated doc.
  • DMouayad: Improve doc.
  • elliotsayes: Improve doc.
  • tmpfs: Improve doc.
  • thomas725: Improve doc.
  • juzi5201314: Improve doc.
  • Voklen: Improve doc.
  • svenstaro: Improve doc.
  • utilForever: Fix typos.
  • not-holar: Fix typos.
  • Stonks3141: Fix doc credit.
  • vimaxwell: Fix doc link.
  • lker-dev: Fix doc link.
  • jaiakash: Fix doc link.
  • feber: Fix doc link.
  • satvikpendem: Little co-work #989.
  • rustui: Fix a typo.
  • escwxyz: Fix a typo.
  • eltociear: Fix a typo.
  • thesimplekid: Fix a typo.
470
likes
0
pub points
97%
popularity

Publisher

verified publishercjycode.com

High-level memory-safe binding generator for Flutter/Dart <-> Rust

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

args, build_cli_annotations, js, meta, path

More

Packages that depend on flutter_rust_bridge