Skip to content

Commit

Permalink
Merge pull request #679 from biklas7/feature/write-meal
Browse files Browse the repository at this point in the history
Allow to record meal data (macro nutrients)
  • Loading branch information
hoffmatteo authored Nov 13, 2023
2 parents 450f91f + f5673c1 commit a88ba2e
Show file tree
Hide file tree
Showing 9 changed files with 1,473 additions and 958 deletions.
2 changes: 2 additions & 0 deletions packages/health/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The plugin supports:
- reading health data using the `getHealthDataFromTypes` method.
- writing health data using the `writeHealthData` method.
- writing workouts using the `writeWorkout` method.
- writing meals on iOS (Apple Health) & Android (Google Fit) using the `writeMeal` method.
- writing audiograms on iOS using the `writeAudiogram` method.
- writing blood pressure data using the `writeBloodPressure` method.
- accessing total step counts using the `getTotalStepsInInterval` method.
Expand Down Expand Up @@ -69,6 +70,7 @@ Note that for Android, the target phone **needs** to have [Google Fit](https://w
| HEADACHE_UNSPECIFIED | MINUTES | yes | | | |
| AUDIOGRAM | DECIBEL_HEARING_LEVEL | yes | | | |
| ELECTROCARDIOGRAM | VOLT | yes | | | Requires Apple Watch to write the data |
| NUTRITION | NO_UNIT | yes | yes | yes | |

## Setup

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
<uses-permission android:name="android.permission.health.READ_BASAL_METABOLIC_RATE"/>
<uses-permission android:name="android.permission.health.READ_RESPIRATORY_RATE"/>
<uses-permission android:name="android.permission.health.WRITE_RESPIRATORY_RATE"/>

<uses-permission android:name="android.permission.health.WRITE_NUTRITION"/>
<uses-permission android:name="android.permission.health.READ_NUTRITION"/>

<application android:label="health_example"
android:icon="@mipmap/ic_launcher">
Expand All @@ -79,8 +80,8 @@
<action android:name="androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE" />
</intent-filter>
</activity>
<!-- For versions starting Android 14, create an activity alias to show the rationale
of Health Connect permissions once users click the privacy policy link. -->
<!-- For versions starting Android 14, create an activity alias to show the rationale
of Health Connect permissions once users click the privacy policy link.
<activity-alias
android:name="ViewPermissionUsageActivity"
android:exported="true"
Expand All @@ -92,7 +93,7 @@
</intent-filter>
</activity-alias>
<meta-data android:name="flutterEmbedding"
--> <meta-data android:name="flutterEmbedding"
android:value="2"/>
</application>
</manifest>
13 changes: 12 additions & 1 deletion packages/health/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class _HealthAppState extends State<HealthApp> {
// // HealthDataType.AUDIOGRAM
// ];

// with coresponsing permissions
// with corresponsing permissions
// READ only
// final permissions = types.map((e) => HealthDataAccess.READ).toList();
// Or READ and WRITE
Expand Down Expand Up @@ -169,6 +169,8 @@ class _HealthAppState extends State<HealthApp> {
success &= await health.writeHealthData(
0.0, HealthDataType.SLEEP_DEEP, earlier, now);

success &= await health.writeMeal(
earlier, now, 1000, 50, 25, 50, "Banana", MealType.SNACK);
// Store an Audiogram
// Uncomment these on iOS - only available on iOS
// const frequencies = [125.0, 500.0, 1000.0, 2000.0, 4000.0, 8000.0];
Expand Down Expand Up @@ -279,6 +281,15 @@ class _HealthAppState extends State<HealthApp> {
subtitle: Text('${p.dateFrom} - ${p.dateTo}'),
);
}
if (p.value is NutritionHealthValue) {
return ListTile(
title: Text(
"${p.typeString} ${(p.value as NutritionHealthValue).mealType}: ${(p.value as NutritionHealthValue).name}"),
trailing:
Text('${(p.value as NutritionHealthValue).calories} kcal'),
subtitle: Text('${p.dateFrom} - ${p.dateTo}'),
);
}
return ListTile(
title: Text("${p.typeString}: ${p.value}"),
trailing: Text('${p.unitString}'),
Expand Down
2 changes: 2 additions & 0 deletions packages/health/example/lib/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const List<HealthDataType> dataTypesIOS = [
HealthDataType.HEADACHE_SEVERE,
HealthDataType.HEADACHE_UNSPECIFIED,
//HealthDataType.ELECTROCARDIOGRAM,
HealthDataType.NUTRITION,
];

/// List of data types available on Android
Expand Down Expand Up @@ -78,4 +79,5 @@ const List<HealthDataType> dataTypesAndroid = [
HealthDataType.WORKOUT,
HealthDataType.RESTING_HEART_RATE,
HealthDataType.FLIGHTS_CLIMBED,
HealthDataType.NUTRITION,
];
Loading

0 comments on commit a88ba2e

Please sign in to comment.