Skip to content

Commit

Permalink
When writing data, check if the type is available on the requested pl…
Browse files Browse the repository at this point in the history
…atform
  • Loading branch information
SlimShadyIAm committed Aug 22, 2024
1 parent 8adfd97 commit dd1f035
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
5 changes: 0 additions & 5 deletions packages/health/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,6 @@ class _HealthAppState extends State<HealthApp> {
type: HealthDataType.HEART_RATE,
startTime: earlier,
endTime: now);
success &= await Health().writeHealthData(
value: 30,
type: HealthDataType.HEART_RATE_VARIABILITY_RMSSD,
startTime: earlier,
endTime: now);
success &= await Health().writeHealthData(
value: 37,
type: HealthDataType.BODY_TEMPERATURE,
Expand Down
4 changes: 4 additions & 0 deletions packages/health/lib/src/health_plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ class Health {
throw ArgumentError(
"Adding workouts should be done using the writeWorkoutData method.");
}
// If not implemented on platform, throw an exception
if (!isDataTypeAvailable(type)) {
throw HealthException(type, 'Not available on platform $platformType');
}
endTime ??= startTime;
if (startTime.isAfter(endTime)) {
throw ArgumentError("startTime must be equal or earlier than endTime");
Expand Down

0 comments on commit dd1f035

Please sign in to comment.