flutter_health 1.1.8

flutter_health #

This library combines both GoogleFit and AppleHealthKit. It support most of the values provided.

Works on from iOS 11.0. Some data types are supported from iOS 12.2.

Supports Android X

Dart package

Gitlab link

#AppleHealthKit First Let's go through apple health kit

Setup #

From Runner, select the Capabilities tab

  • Enable HealthKit
  • Check the Clinical Health Records box.

Then in the info.plist, Add string values for the following:

  • NSHealthUpdateUsageDescription
  • NSHealthShareUsageDescription

How to use #

Check if Apple Health is available on the device #

await FlutterHealth.checkIfHealthDataAvailable()

Request authorization for the data types supported by the plugin #

await FlutterHealth.requestAuthorization()

######For now, you can request all of the options provided by the library

Get the samples of data types authorized by the user within the given time range #

await FlutterHealth.getBodyFat(startDate, endDate)
await FlutterHealth.getHeartRate(startDate, endDate)
await FlutterHealth.getBloodPressureSys(startDate, endDate)

...

Data will be returning as a List of an object called HKHealthData. This object has the following attributes: #

 double value;
 String unit;
 int dateFrom;
 int dateTo;

You can get those values with this library: #

Tested:

  • bodyFatPercentage
  • height
  • bodyMassIndex
  • waistCircumference
  • stepCount
  • basalEnergyBurned
  • activeEnergyBurned
  • heartRate
  • restingHeartRate
  • walkingHeartRateAverage
  • bodyTemperature
  • bloodPressureSystolic
  • bloodPressureDiastolic
  • oxygenSaturation
  • bloodGlucose
  • electrodermalActivity

Could not be tested without a watch:

  • highHeartRateEvent
  • lowHeartRateEvent
  • irregularHeartRhythmEvent

Full Example #

 await FlutterHealth.checkIfHealthDataAvailable();
 bool _isAuthorized = true;
 DateTime startDate = DateTime.utc(2018);
 DateTime endDate = DateTime.now();
 var _dataList = List<HKHealthData>();
 
 _isAuthorized = await FlutterHealth.requestAuthorization();
 if (_isAuthorized) _dataList.addAll(await FlutterHealth.getBodyFat(startDate, endDate));
 if (_isAuthorized) _dataList.addAll(await FlutterHealth.getHeight(startDate, endDate));
 if (_isAuthorized) _dataList.addAll(await FlutterHealth.getBodyMass(startDate, endDate));
 if (_isAuthorized) _dataList.addAll(await FlutterHealth.getWaistCircumference(startDate, endDate));
 if (_isAuthorized) _dataList.addAll(await FlutterHealth.getStepCount(startDate, endDate));
 if (_isAuthorized) _dataList.addAll(await FlutterHealth.getBasalEnergyBurned(startDate, endDate));
 if (_isAuthorized) _dataList.addAll(await FlutterHealth.getActiveEnergyBurned(startDate, endDate));
 if (_isAuthorized) _dataList.addAll(await FlutterHealth.getHeartRate(startDate, endDate));
 if (_isAuthorized) _dataList.addAll(await FlutterHealth.getRestingHeartRate(startDate, endDate));
 if (_isAuthorized) _dataList.addAll(await FlutterHealth.getWalkingHeartRate(startDate, endDate));
 if (_isAuthorized) _dataList.addAll(await FlutterHealth.getBodyTemperature(startDate, endDate));
 if (_isAuthorized) _dataList.addAll(await FlutterHealth.getBloodPressureSys(startDate, endDate));
 if (_isAuthorized) _dataList.addAll(await FlutterHealth.getBloodPressureDia(startDate, endDate));
 if (_isAuthorized) _dataList.addAll(await FlutterHealth.getBloodOxygen(startDate, endDate));
 if (_isAuthorized) _dataList.addAll(await FlutterHealth.getBloodGlucose(startDate, endDate));
 if (_isAuthorized) _dataList.addAll(await FlutterHealth.getElectrodermalActivity(startDate, endDate));
 if (_isAuthorized) _dataList.addAll(await FlutterHealth.getHKHighHeart(startDate, endDate));
 if (_isAuthorized) _dataList.addAll(await FlutterHealth.getHKLowHeart(startDate, endDate));
 if (_isAuthorized) _dataList.addAll(await FlutterHealth.getHKIrregular(startDate, endDate));

#GoogleFit

Setup #

For GoogleFit, the initial setup is a bit longer, and can get frustrating. Just follow this setup.

How to use #

Request authorization for the data types supported by the plugin #

await FlutterHealth.requestAuthorization()

######For now, you can request all of the options provided by the library

Get the samples of data types authorized by the user within the given time range #

For all data

await FlutterHealth.getGFAllData(startDate, endDate)

For specific type

await FlutterHealth.getGFBodyFat(startDate, endDate)
await FlutterHealth.getGFHeartRate(startDate, endDate)
await FlutterHealth.getGFBloodPressureSys(startDate, endDate)

...

Data will be returning as a List of an object called GFHealthData. This object has the following attributes: #

 String value;
 String value2;
 String unit;
 int dateFrom;
 int dateTo;

You can get those GoogleFit values with this library: #

  • bodyFatPercentage
  • height
  • stepCount
  • calories
  • heartRate
  • bodyTemperature
  • bloodPressure
  • oxygenSaturation
  • bloodGlucose

1.1.8 #

Apple health kit for flutter (Flutter Health) initial release

You can use it to get any of the following

Tested:

  • bodyFatPercentage
  • height
  • bodyMassIndex
  • waistCircumference
  • stepCount
  • basalEnergyBurned
  • activeEnergyBurned
  • heartRate
  • restingHeartRate
  • walkingHeartRateAverage
  • bodyTemperature
  • bloodPressureSystolic
  • bloodPressureDiastolic
  • oxygenSaturation
  • bloodGlucose
  • electrodermalActivity

Could not be tested:

  • highHeartRateEvent
  • lowHeartRateEvent
  • irregularHeartRhythmEvent

example/README.md

flutter_health_example #

Demonstrates how to use the flutter_health plugin.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_health: ^1.1.8

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_health/flutter_health.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
50
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
75
Learn more about scoring.

We analyzed this package on Aug 18, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19
  • Flutter: 1.7.8+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Fix lib/flutter_health.dart. (-1 points)

Analysis of lib/flutter_health.dart reported 2 hints:

line 162 col 17: The stack trace variable 's' isn't used and can be removed.

line 169 col 9: The value of the local variable 'healthData' isn't used.

Format lib/generated/i18n.dart.

Run flutter format to format lib/generated/i18n.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test