Skip to content

Commit

Permalink
Merge pull request #1119 from cph-cachet/bardram/helth-docs
Browse files Browse the repository at this point in the history
Version 12.0.1
  • Loading branch information
bardram authored Jan 16, 2025
2 parents 5d8b1b3 + 65f9368 commit f1f4ee0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
5 changes: 5 additions & 0 deletions packages/health/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 12.0.1

* Update of API and README doc
* Fix [#1118](https://github.com/cph-cachet/flutter-plugins/issues/1118)

## 12.0.0

* **BREAKING** This release introduces a significant architectural change to the `health` plugin by removing the `singleton` pattern.
Expand Down
26 changes: 15 additions & 11 deletions packages/health/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,16 @@ android.useAndroidX=true

See the example app for detailed examples of how to use the Health API.

The Health plugin is used via the `Health()` singleton using the different methods for handling permissions and getting and adding data to Apple Health or Google Health Connect.
A instance of the Health plugin is create using the `Health()` constructor and is subsequently configured calling the `configure` method. Once configured, the plugin can be used for handling permissions and getting and adding data to Apple Health or Google Health Connect.
Below is a simplified flow of how to use the plugin.

```dart
// Global Health instance
final health = Health();
// configure the health plugin before use.
Health().configure();
await health.configure();
// define the types to get
Expand All @@ -161,12 +165,12 @@ Below is a simplified flow of how to use the plugin.
];
// requesting access to the data types before reading them
bool requested = await Health().requestAuthorization(types);
bool requested = await health.requestAuthorization(types);
var now = DateTime.now();
// fetch health data from the last 24 hours
List<HealthDataPoint> healthData = await Health().getHealthDataFromTypes(
List<HealthDataPoint> healthData = await health.getHealthDataFromTypes(
now.subtract(Duration(days: 1)), now, types);
// request permissions to write steps and blood glucose
Expand All @@ -175,20 +179,20 @@ Below is a simplified flow of how to use the plugin.
HealthDataAccess.READ_WRITE,
HealthDataAccess.READ_WRITE
];
await Health().requestAuthorization(types, permissions: permissions);
await health.requestAuthorization(types, permissions: permissions);
// write steps and blood glucose
bool success = await Health().writeHealthData(10, HealthDataType.STEPS, now, now);
success = await Health().writeHealthData(3.1, HealthDataType.BLOOD_GLUCOSE, now, now);
bool success = await health.writeHealthData(10, HealthDataType.STEPS, now, now);
success = await health.writeHealthData(3.1, HealthDataType.BLOOD_GLUCOSE, now, now);
// you can also specify the recording method to store in the metadata (default is RecordingMethod.automatic)
// on iOS only `RecordingMethod.automatic` and `RecordingMethod.manual` are supported
// Android additionally supports `RecordingMethod.active` and `RecordingMethod.unknown`
success &= await Health().writeHealthData(10, HealthDataType.STEPS, now, now, recordingMethod: RecordingMethod.manual);
success &= await health.writeHealthData(10, HealthDataType.STEPS, now, now, recordingMethod: RecordingMethod.manual);
// get the number of steps for today
var midnight = DateTime(now.year, now.month, now.day);
int? steps = await Health().getTotalStepsInInterval(midnight, now);
int? steps = await health.getTotalStepsInInterval(midnight, now);
```

### Health Data
Expand Down Expand Up @@ -266,7 +270,7 @@ Google Health Connect and Apple HealthKit both provide ways to distinguish sampl
As such, when fetching data you have the option to filter the fetched data by recording method as such:

```dart
List<HealthDataPoint> healthData = await Health().getHealthDataFromTypes(
List<HealthDataPoint> healthData = await health.getHealthDataFromTypes(
types: types,
startTime: yesterday,
endTime: now,
Expand Down Expand Up @@ -294,7 +298,7 @@ If you have a list of data points, duplicates can be removed with:

```dart
List<HealthDataPoint> points = ...;
points = Health().removeDuplicates(points);
points = health.removeDuplicates(points);
```

## Data Types
Expand Down
5 changes: 5 additions & 0 deletions packages/health/lib/health.json.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ void _registerFromJsonFunctions() {
ElectrocardiogramHealthValue(voltageValues: []),
ElectrocardiogramVoltageValue(voltage: 12, timeSinceSampleStart: 0),
NutritionHealthValue(),
MenstruationFlowHealthValue(flow: null, dateTime: DateTime.now()),
InsulinDeliveryHealthValue(
units: 0.0,
reason: InsulinDeliveryReason.NOT_SET,
),
]);

_fromJsonFunctionsRegistered = true;
Expand Down
2 changes: 1 addition & 1 deletion packages/health/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: health
description: Wrapper for Apple's HealthKit on iOS and Google's Health Connect on Android.
version: 12.0.0
version: 12.0.1
homepage: https://github.com/cph-cachet/flutter-plugins/tree/master/packages/health

environment:
Expand Down

0 comments on commit f1f4ee0

Please sign in to comment.