Health 4.0.0 Flutter Plugin Release

Summary of changes:

  • Support for Workouts on iOS (Apple Health) and Android (Google Fit)
  • Support for Audiograms on iOS (Apple Health)
  • Added more units in the HealthDataUnit
  • Removed the requestPermissions method
  • Updated HealthDataPoint to support NumericHealthValue, AudiogramHealthValue and WorkoutHealthValue

As of Health 4.0.0 the plugin now supports workouts on Apple Health for iOS and using Google Fit for Android. Additionally, Health 4.0.0 also adds support for Audiograms on iOS.

Workouts

Workouts are time periods where the user performed an exercise or exercise related activity e.g., walking, playing hockey or doing yoga. The list in the package ReadMe shows all the supported types of workouts for each operating system.

In Health 4.0.0 each workout also has the option to include additional information about the distance and energy burned during the workout. Both parameters are optional and can be left out if not needed.

On iOS the plugin also supports units for both the distance and energy burned. These can be specified using the HealthDataUnit but on Android the plugin uses default values of meter and kilocalorie respectively.
Both platforms use meter and kilocalorie for retrieving data!

APPLE HEALTH

To work with Apple Health the Health plugin uses HealthKit to access, retrieve and manage Workouts. The plugin saves a Workout as the native HKWorkout with a type based on the HKWorkoutActivityType .

The Apple documentation on HealthKit’s HKWorkout can be found here.

GOOGLE FIT

On Android no native support exists for storing and managing health data, so the plugin uses Google Fit. Google Fit has a type named Workout, but this is limited to strength exercises, so instead the plugin uses the Activities datatype.
Activities are stored in Sessions where multiple activity types can be mixed. However, to bridge the gap between Android and iOS the Health plugin stores each activity type as a single session instead.

On Android, the distance of a workout requires the ACCESS_FINE_LOCATION permission, as it is restricted information. If the permission is not given, the Health plugin will default to activity type and energy burned.

Google documentation on Google Fit’s Sessions can be found here and documentation for Activities can be found here.


NOTE – Google is deprecating the Fit API and moving to Health Connect. This will be supported in a future release.

Example

Adding a Workout:

await health.writeWorkoutData(
      HealthWorkoutActivityType.RUNNING,
      earlier, 
      now,
      // The following are optional parameters
      // UNITS are relevant on iOS only
      totalEnergyBurned: 230,
      totalEnergyBurnedUnit: HealthDataUnit.KILOCALORIE, 
      totalDistance: 1234,
      totalDistanceUnit: HealthDataUnit.FOOT,
    );

Supported workouts

The entire list of supported workout types can be found in the package ReadMe. There are a few changes:

  • Some workouts are platform specific while others work on both.
  • A few workout types have been merged on one platform e.g. RUNNING_JOGGING, RUNNING_SAND and RUNNING_TREADMILL are Android values but iOS only has RUNNING, so the aforementioned values will all be stored as RUNNING if used on iOS.
  • A few names are changed to simplify the activity types e.g. CYCLING on iOS which is changed to BIKING as it is named on Android, instead of having 2 values represent the same activity type.

Audiogram

In Health 4.0.0, Audiograms are supported on iOS. An Audiogram consists of one or more sensitivity points. Each sensitivity point is described by the FREQUENCY tested in HERTZ along with the LEFT EAR SENSITIVITY and RIGHT EAR SENSITIVITY both in DECIBEL HEARING LEVEL. This unit measures the intensity of the sound relative to the quietest sound a typical young, healthy individual can hear.

Per user request, the Audiogram contains the METADATA optional argument to allow users to include addtional information. The meta data is a Map of information. The keys used for meta data in HealthKit can be found here.

Below is an example where the user added the sound device used for the audiogram.

Example

Adding audiogram

    const frequencies = [125.0, 500.0, 1000.0, 2000.0, 4000.0, 8000.0]; // hertz
    const leftEarSensitivities = [49.0, 54.0, 89.0, 52.0, 77.0, 35.0]; // decibel
    const rightEarSensitivities = [76.0, 66.0, 90.0, 22.0, 85.0, 44.5];

    await health.writeAudiogram(
      frequencies,
      leftEarSensitivities,
      rightEarSensitivities,
      now,
      now,
      metadata: {
        "HKExternalUUID": "uniqueID",
        "HKDeviceName": "bluetooth headphone",
      },
    );