Installing dependencies

Next, we need to install a few build-time and runtime dependencies.

Build-time dependencies

These depdencies are required only in build-time:

An easy way to install most of these dependencies is to run:

cargo install flutter_rust_bridge_codegen
dart pub global activate ffigen
# if building for iOS or MacOS
cargo install cargo-xcode

Dart dependencies

On the Dart side, flutter_rust_bridge is the required runtime component of flutter_rust_bridge_codegen. If you plan to use enum structs in Rust, the following dependencies are also needed:

  • build_runner (dev)
  • freezed (dev)
  • freezed_annotation

Their usage is explained in Using build_runner.

flutter pub add flutter_rust_bridge
# if using Dart codegen
flutter pub add -d build_runner
flutter pub add -d freezed
flutter pub add freezed_annotation

Rust dependencies

Similar to Dart, Rust requires the flutter_rust_bridge runtime component for support.

Add these lines to Cargo.toml:

+flutter_rust_bridge = "1"

If you wish to return a Result, keep in mind that this library can only run codegen for anyhow::Result.