Skip to content

Commit 124036a

Browse files
authored
Merge pull request #1188 from cph-cachet:health12/1169nutrition-null
Fix `meal_type` null issue in `NutritionHealthValue`
2 parents 0294e69 + 83969c3 commit 124036a

4 files changed

Lines changed: 29 additions & 7 deletions

File tree

packages/health/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
* iOS: Add `deviceModel` in returned Health data to identify the device that generated the data of the receiver. (in iOS `source_name` represents the revision of the source responsible for saving the receiver.)
44
* Android: Add read health data in background - PR [#1184](https://github.com/cph-cachet/flutter-plugins/pull/1184)
5+
* Fix [#1169](https://github.com/cph-cachet/flutter-plugins/issues/1169) where `meal_type` property in `Nutrition` was null always
56

67
## 12.1.0
78

packages/health/example/lib/main.dart

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,27 @@ class HealthAppState extends State<HealthApp> {
197197
});
198198
}
199199

200+
Future<void> writeNutritionDataTest() async {
201+
final now = DateTime.now();
202+
final earlier = now.subtract(const Duration(minutes: 20));
203+
204+
// Add nutrition data
205+
bool success = await health.writeMeal(
206+
mealType: MealType.DINNER,
207+
startTime: earlier,
208+
endTime: now,
209+
caloriesConsumed: 1000,
210+
carbohydrates: 50,
211+
protein: 25,
212+
fatTotal: 50,
213+
name: "Banana",
214+
);
215+
216+
setState(() {
217+
_state = success ? AppState.DATA_ADDED : AppState.DATA_NOT_ADDED;
218+
});
219+
}
220+
200221
/// Add some random health data.
201222
/// Note that you should ensure that you have permissions to add the
202223
/// following data types.
@@ -740,7 +761,7 @@ class HealthAppState extends State<HealthApp> {
740761
if (p.value is NutritionHealthValue) {
741762
return ListTile(
742763
title: Text(
743-
"${p.typeString} ${(p.value as NutritionHealthValue).mealType}: ${(p.value as NutritionHealthValue).name}"),
764+
"${p.typeString} ${(p.value as NutritionHealthValue).meal_type}: ${(p.value as NutritionHealthValue).name}"),
744765
trailing:
745766
Text('${(p.value as NutritionHealthValue).calories} kcal'),
746767
subtitle: Text('${p.dateFrom} - ${p.dateTo}\n${p.recordingMethod}'),

packages/health/lib/health.g.dart

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/health/lib/src/health_value_types.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ class NutritionHealthValue extends HealthValue {
426426
String? name;
427427

428428
/// The type of meal.
429-
String? mealType;
429+
String? meal_type;
430430

431431
/// The amount of calories in kcal.
432432
double? calories;
@@ -556,7 +556,7 @@ class NutritionHealthValue extends HealthValue {
556556

557557
NutritionHealthValue({
558558
this.name,
559-
this.mealType,
559+
this.meal_type,
560560
this.calories,
561561
this.protein,
562562
this.fat,
@@ -625,7 +625,7 @@ class NutritionHealthValue extends HealthValue {
625625
name: ${name.toString()},
626626
carbs: ${carbs.toString()},
627627
caffeine: ${caffeine.toString()},
628-
mealType: $mealType,
628+
mealType: $meal_type,
629629
vitaminA: ${vitaminA.toString()},
630630
b1Thiamine: ${b1Thiamine.toString()},
631631
b2Riboflavin: ${b2Riboflavin.toString()},
@@ -668,7 +668,7 @@ class NutritionHealthValue extends HealthValue {
668668
bool operator ==(Object other) =>
669669
other is NutritionHealthValue &&
670670
other.name == name &&
671-
other.mealType == mealType &&
671+
other.meal_type == meal_type &&
672672
other.calories == calories &&
673673
other.protein == protein &&
674674
other.fat == fat &&

0 commit comments

Comments
 (0)