Skip to content

Commit

Permalink
Merge pull request #933 from cph-cachet/bardram/health-update
Browse files Browse the repository at this point in the history
Health version 10.1.0
  • Loading branch information
bardram authored Mar 30, 2024
2 parents b43a07c + 211a2b7 commit b62d2e5
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 40 deletions.
6 changes: 6 additions & 0 deletions packages/health/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 10.1.0

* fix of error in `WorkoutSummary` JSON serialization.
* empty value check for calories nutrition, PR [#926](https://github.com/cph-cachet/flutter-plugins/pull/926)

## 10.0.0

* **BREAKING** The plugin now works as a singleton using `Health()` to access it (instead of creating an instance of `HealthFactory`).
Expand All @@ -6,6 +11,7 @@
* Support for new data types:
* body water mass, PR [#917](https://github.com/cph-cachet/flutter-plugins/pull/917)
* caffeine, PR [#924](https://github.com/cph-cachet/flutter-plugins/pull/924)
* workout summary, manual entry and new health data types, PR [#920](https://github.com/cph-cachet/flutter-plugins/pull/920)
* Fixed `SleepSessionRecord`, PR [#928](https://github.com/cph-cachet/flutter-plugins/pull/928)
* Update to API and README docs
* Upgrade to Dart 3.2 and Flutter 3.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3002,7 +3002,7 @@ class HealthPlugin(private var channel: MethodChannel? = null) :
}
is BodyTemperatureRecord ->
return listOf(
mapOf<String, Any>(
mapOf<String, Any>(w
"value" to
record.temperature
.inCelsius,
Expand Down
6 changes: 4 additions & 2 deletions packages/health/ios/Classes/SwiftHealthPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,10 @@ public class SwiftHealthPlugin: NSObject, FlutterPlugin {

var nutrition = Set<HKSample>()

let caloriesSample = HKQuantitySample(type: HKSampleType.quantityType(forIdentifier: .dietaryEnergyConsumed)!, quantity: HKQuantity(unit: HKUnit.kilocalorie(), doubleValue: calories), start: dateFrom, end: dateTo, metadata: metadata)
nutrition.insert(caloriesSample)
if(calories > 0) {
let caloriesSample = HKQuantitySample(type: HKSampleType.quantityType(forIdentifier: .dietaryEnergyConsumed)!, quantity: HKQuantity(unit: HKUnit.kilocalorie(), doubleValue: calories), start: dateFrom, end: dateTo, metadata: metadata)
nutrition.insert(caloriesSample)
}

if(carbs > 0) {
let carbsSample = HKQuantitySample(type: HKSampleType.quantityType(forIdentifier: .dietaryCarbohydrates)!, quantity: HKQuantity(unit: HKUnit.gram(), doubleValue: carbs), start: dateFrom, end: dateTo, metadata: metadata)
Expand Down
2 changes: 1 addition & 1 deletion packages/health/lib/health.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';

part 'src/data_types.dart';
part 'src/heath_data_types.dart';
part 'src/functions.dart';
part 'src/health_data_point.dart';
part 'src/health_value_types.dart';
Expand Down
8 changes: 4 additions & 4 deletions packages/health/lib/health.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 1 addition & 6 deletions packages/health/lib/src/health_data_point.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,7 @@ class HealthDataPoint {
dataPoint["total_distance"] != null ||
dataPoint["total_energy_burned"] != null ||
dataPoint["total_steps"] != null) {
workoutSummary = WorkoutSummary(
dataPoint["workout_type"] as String? ?? '',
dataPoint["total_distance"] as num? ?? 0,
dataPoint["total_energy_burned"] as num? ?? 0,
dataPoint["total_steps"] as num? ?? 0,
);
workoutSummary = WorkoutSummary.fromHealthDataPoint(dataPoint);
}

return HealthDataPoint(
Expand Down
File renamed without changes.
45 changes: 20 additions & 25 deletions packages/health/lib/src/workout_summary.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
part of '../health.dart';

/// A [WorkoutSummary] object store vary metrics of a workout.
/// * totalDistance - The total distance that was traveled during a workout.
/// * totalEnergyBurned - The amount of energy that was burned during a workout.
/// * totalSteps - The count of steps was burned during a workout.
///
/// * [workoutType] - The type of workout. See [HealthWorkoutActivityType] for available types.
/// * [totalDistance] - The total distance that was traveled during a workout.
/// * [totalEnergyBurned] - The amount of energy that was burned during a workout.
/// * [totalSteps] - The number of steps during a workout.
@JsonSerializable(fieldRename: FieldRename.snake, includeIfNull: false)
class WorkoutSummary {
/// Workout type.
Expand All @@ -18,12 +20,21 @@ class WorkoutSummary {
/// The total steps value of the workout.
num totalSteps;

WorkoutSummary(
this.workoutType,
this.totalDistance,
this.totalEnergyBurned,
this.totalSteps,
);
WorkoutSummary({
required this.workoutType,
required this.totalDistance,
required this.totalEnergyBurned,
required this.totalSteps,
});

/// Create a [WorkoutSummary] based on a health data point from native data format.
factory WorkoutSummary.fromHealthDataPoint(dynamic dataPoint) =>
WorkoutSummary(
workoutType: dataPoint['workout_type'] as String? ?? '',
totalDistance: dataPoint['total_distance'] as num? ?? 0,
totalEnergyBurned: dataPoint['total_energy_burned'] as num? ?? 0,
totalSteps: dataPoint['total_steps'] as num? ?? 0,
);

/// Create a [HealthDataPoint] from json.
factory WorkoutSummary.fromJson(Map<String, dynamic> json) =>
Expand All @@ -32,22 +43,6 @@ class WorkoutSummary {
/// Convert this [HealthDataPoint] to json.
Map<String, dynamic> toJson() => _$WorkoutSummaryToJson(this);

// /// Converts a json object to the [WorkoutSummary]
// factory WorkoutSummary.fromJson(json) => WorkoutSummary(
// json['workoutType'],
// json['totalDistance'],
// json['totalEnergyBurned'],
// json['totalSteps'],
// );

// /// Converts the [WorkoutSummary] to a json object
// Map<String, dynamic> toJson() => {
// 'workoutType': workoutType,
// 'totalDistance': totalDistance,
// 'totalEnergyBurned': totalEnergyBurned,
// 'totalSteps': totalSteps
// };

@override
String toString() => '$runtimeType - '
'workoutType: $workoutType'
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 HealthKit on iOS and Google Fit and Health Connect on Android.
version: 10.0.0
version: 10.1.0
homepage: https://github.com/cph-cachet/flutter-plugins/tree/master/packages/health

environment:
Expand Down

0 comments on commit b62d2e5

Please sign in to comment.