website/docs/quickstart.md
import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';
:::info
If you like to setup in one command:
cargo install flutter_rust_bridge_codegen && flutter_rust_bridge_codegen create my_app && cd my_app && flutter run
:::
After Flutter and Rust are
installed,
install flutter_rust_bridge using any method:
cargo install flutter_rust_bridge_codegen
cargo binstall flutter_rust_bridge_codegen
Suppose your app is to be named my_app, then execute this. <small>(Use --help to see more options, e.g. package
name)</small>
flutter_rust_bridge_codegen create my_app
Execute the following in the root folder of your Flutter project:
flutter_rust_bridge_codegen integrate
Please refer to this page.
</TabItem> <TabItem value="Flutter Package">Execute the following command to create a shareable Flutter package that can be used across multiple Flutter applictions:
flutter_rust_bridge_codegen create my_package --template plugin
Please visit this page.
</TabItem> </Tabs>import DirectoryStructureBriefExplain from './snippets/_directory-structure-brief-explain.mdx'; import DirectoryStructureBriefList from './snippets/_directory-structure-brief-list.mdx';
<DirectoryStructureBriefExplain/>For more details, please see this page.
Use your favorite method to run the app (Flutter official doc), as if it is just a normal Flutter project. For example:
flutter run
P.S. The build-web command: Because Flutter Web does not have a build hook yet
(corresponding issue).
flutter_rust_bridge_codegen build-web
# ... or any other standard Flutter ways
flutter run --web-header=Cross-Origin-Opener-Policy=same-origin --web-header=Cross-Origin-Embedder-Policy=require-corp
Then, you will see a greeting from Rust, displayed in Flutter (Dart).
Suppose we add a super-simple Rust function in rust/src/api/simple.rs
(see next chapter for all features):
pub fn hello(a: String) -> String { a.repeat(2) }
With all glue code automatically generated, we can call it in Dart (lib/main.dart):
var result = await hello(a: "Hi");
await is for asynchronous code, a very frequently used feature in Dart.We need to execute the code generator whenever the Rust code is changed,
or use --watch to automatically re-generate when code changes:
flutter_rust_bridge_codegen generate --watch
On one hand, if you like to see a live demo, please visit the next page.
On the other hand, the guides chapter introduces all features, customizations, common scenario how-tos, etc. There are a lot of documentations, but there is no need to learn all in details. Instead:
import Intuition from './snippets/_tip-use-intuition.mdx';
<Intuition/>