You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
samples/experimental/pedometer
dependabot[bot] 0a1ec8eea9
Bump ffigen from 8.0.2 to 9.0.0 in /experimental/pedometer (#1944)
1 year ago
..
android Rebuild runners (#1725) 1 year ago
example Enable Material 3 on `experimental/pedometer` (#1949) 1 year ago
ios Add `experimental/pedometer` (#1587) 1 year ago
lib Update pedometer to jni and jnigen:0.5.0 (#1863) 1 year ago
src Update pedometer to jni and jnigen:0.5.0 (#1863) 1 year ago
.gitignore Add `experimental/pedometer` (#1587) 1 year ago
.metadata [experimental/pedometer] Use `jnigen` and `jni` version from pub instead of git url. (#1655) 1 year ago
CHANGELOG.md Add `experimental/pedometer` (#1587) 1 year ago
LICENSE Add `experimental/pedometer` (#1587) 1 year ago
README.md Explain the pedometer example directory in its README (#1928) 1 year ago
analysis_options.yaml Add `experimental/pedometer` (#1587) 1 year ago
ffigen.yaml Add `experimental/pedometer` (#1587) 1 year ago
jnigen.yaml Update pedometer to jni and jnigen:0.5.0 (#1863) 1 year ago
pubspec.yaml Bump ffigen from 8.0.2 to 9.0.0 in /experimental/pedometer (#1944) 1 year ago

README.md

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 here. You can regenerate them by following the steps below.

FFIgen

Configuration for FFIgen is here for the CoreMotion framework. FFIgen currently does not support autogenerating the code to handle callbacks. So, there were a few steps needed to appropriately handle callbacks in Objective-C. You can read more here.

dart run ffigen --config ffigen.yaml

JNIgen

Configuration for JNIgen is here for the HealthConnect API.

  1. cd Example && flutter build apk
  2. cd .. && dart run jnigen --config jnigen.yaml

Running the example app

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

Note that step counting is only available on physical devices.

iOS

  • flutter run
  • Allow pedometer app access to step counting

Android

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

Project stucture

  • 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 which calls into the native code using dart:ffi.

  • platform folders (ios etc.): Contains 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.