Flutter is a popular cross-platform mobile app development framework. Mopro Flutter shows an example of integrating ZK-proving into a Flutter app, allowing for streamlined creation of ZK-enabled mobile apps.
Important
Please refer to the latest mopro documentation for the most up-to-date information.
-
Install Flutter
If Flutter is not already installed, you can follow the official Flutter installation guide for your operating system.
-
Check Flutter Environment
After installing Flutter, verify that your development environment is properly set up by running the following command in your terminal:
flutter doctor
This command will identify any missing dependencies or required configurations.
-
Install Flutter Dependencies
Navigate to the root directory of the project in your terminal and run:
flutter pub get
This will install the necessary dependencies for the project.
- Open the project in VS Code.
- Open the "Run and Debug" panel.
- Start an emulator (iOS/Android) or connect your physical device.
- Select "example" in the run menu and press "Run".
If you prefer using the terminal to run the app, use the following steps:
-
For Android:
Ensure you have an Android emulator running or a device connected. Then run:
flutter run
-
For iOS:
Make sure you have an iOS simulator running or a device connected. Then run:
flutter run
The example app comes with a simple prover generated from a Circom circuit. To integrate your own prover, follow the steps below.
Warning
In the frb branch, the example app uses flutter_rust_bridge to generate bindings. If you need to work with mopro-ffi or mopro-cli versions earlier than 0.3.0, please switch to the main branch or the v0.2.0 tag.
- Install the latest mopro CLI on GitHub
git clone https://github.com/zkmopro/mopro
cd mopro/cli
cargo install --path .- Follow the Getting Started guide to run
(select your preferred adapter) and then
mopro init
to generate themopro build
mopro_flutter_bindings.
After running mopro build, copy the generated mopro_flutter_bindings. If you add new functions with flutter_rust_bridge and want to use them in Flutter, run mopro build again to regenerate and update the bindings.
-
Place your
.zkeyfile in your app's assets folder. For example, to run the included example app, you need to replace the.zkeyatassets/multiplier2_final.zkeywith your file. If you change the.zkeyfile name, don't forget to update the asset definition in your app'spubspec.yaml:assets: - assets/your_new_zkey_file.zkey
-
Load the new
.zkeyfile properly in your Dart code. For example, update the file path inlib/main.dart:var inputs = "{\"a\":[\"3\"],\"b\":[\"5\"]}"; proofResult = await generateCircomProof( zkeyPath: zkeyPath, circuitInputs: inputs, proofLib: ProofLib.arkworks);
Don't forget to modify the input values for your specific case!
Open the ./android directory in Android Studio. You will be able to browse to the plugin code in Android and Project view.
-
Start an emulator or simulator
-
iOS: Open the iOS simulator via Xcode or
open -a Simulator. -
Android: Launch an emulator using Android Studio or
emulator -avd <your_avd_name>.[!NOTE]
If you encounter the errorcommand not found: emulator, ensure the emulator binary is present in one of the following locations:~/Library/Android/sdk/emulator/emulator~/Android/Sdk/emulator/emulator
To resolve this issue, update your shell configuration file (likely
~/.zshrc) by adding the following lines:export ANDROID_SDK_ROOT=~/Library/Android/sdk export PATH=$PATH:$ANDROID_SDK_ROOT/emulator
After making these changes, verify that the issue is resolved by running:
emulator -list-avds
-
-
Run the integration test
flutter test integration_test/plugin_integration_test.dartMake sure you're using a real or virtual device (not just a Dart VM), as integration tests require it.
To run unit and widget tests (headless, using Dart VM):
flutter testThese are ideal for testing individual widgets, business logic, and pure Dart code.