1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-08 13:58:47 +00:00
Files
samples/pedometer
Eric Windmill 2999d738b8 Dart 3.9 / Flutter 3.35 [first LLM release] (#2714)
I got carried away with Gemini and basically rewrote CI and the release
process for the new LLM reality. This work was largely completed by
Gemini.

- Bump all SDK versions to the current beta (3.9.0-0)
- Run `flutter channel beta`
- Wrote `ci_script.dart` to replace the bash scripts
- Converted repository to pub workspace #2499 
- Added llm.md and release.md
- Added redirect for deprecated Samples Index

## Pre-launch Checklist

- [x] I read the [Flutter Style Guide] _recently_, and have followed its
advice.
- [x] I signed the [CLA].
- [x] I read the [Contributors Guide].
- [x] I have added sample code updates to the [changelog].
- [x] I updated/added relevant documentation (doc comments with `///`).
2025-08-14 12:26:24 -07:00
..
2025-02-12 18:08:01 -05:00
2025-02-12 18:08:01 -05:00
2025-02-12 18:08:01 -05:00
2025-02-12 18:08:01 -05:00
2025-02-12 18:08:01 -05:00
2025-02-12 18:08:01 -05:00
2025-02-12 18:08:01 -05:00
2025-02-12 18:08:01 -05:00
2025-02-12 18:08:01 -05:00
2025-02-12 18:08:01 -05:00

FFIgen + JNIgen pedometer

This is a demo for some of our tooling around calling platform APIs directly from dart code. This repository represents a demo of a plugin that leverages FFIgen & JNIgen. There is also an example pedometer app that uses the bindings generated from these tools.

  • FFIgen is used to generate bindings for C, Objective-C and Swift APIs.
  • JNIgen is used to generate bindings for Java and Kotlin APIs.

These tools are both experimental and are currently a work in progress. If you find any issues or have feedback, please file it on the corresponding GitHub repositories.

Re-generating bindings

The bindings that allow the Dart code to call the platform code have already been generated in the \lib folder. You can regenerate them by following the steps below:

FFIgen

Configuration of FFIgen for the CoreMotion framework is in the ffigen.yaml file. FFIgen currently does not support autogenerating code to handle callbacks. So, there are a few extra steps needed to appropriately handle callbacks in Objective-C. You can read more about this limitation on dart.dev.

dart run ffigen --config ffigen.yaml

JNIgen

Configuration of JNIgen for the HealthConnect API is in the jnigen.yaml file.

  1. Build an Android APK file from the example app. Currently, JNIgen requires at least one APK build to obtain the classpaths of Android Gradle libraries.

    cd example && flutter build apk
    
  2. Return to the /pedometer directory and run jnigen:

    cd .. && dart run jnigen --config jnigen.yaml
    

Running the example app

The example app is located in the /example directory, and the following commands assume they are being run from that location.

Note that step counting is only available on physical devices.

iOS

  • Run flutter run and choose your physical device.
  • Allow the pedometer app access to step counting.

Android

  • Make sure that Google Fit is installed (to ensure that steps are being counted).
  • Run flutter run and choose your physical device.
  • Install Health Connect and grant access to Google Fit and the jni_demo app.

Project structure

  • src: Contains the native source code, and a CMakeLists.txt file for building that source code into a dynamic library.

  • lib: Contains the Dart code that defines the API of the plugin and calls into the native code using dart:ffi.

  • platform folders (ios etc.): Contain the build files for building and bundling the native code library with the platform application.

  • example: Contains the native source code for building that source code into a dynamic library.