curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
nano ~/.bash_profile
Then add export PATH="$PATH:$HOME/.cargo/bin"
wasm-pack --version
cargo new <LIBRARY_NAME> --lib
Go to src/lib.rs
, then replace with something like:
#[no_mangle]
pub extern "C" fn add(a: i32, b: i32) -> i32 {
a + b
}
Add the following to cargo.toml
[lib]
crate-type = ["cdylib"]
[dependencies]
wasm-bindgen = "0.2"
wasm-pack build --target web
Open the pkg
folder and the compliked .wasm
files should be there
Copy the .wasm
files to the Flutter project's web/
folder and check the Flutter code in this example project on how to load them.