writeWorkoutData method
Future<bool>
writeWorkoutData(
- HealthWorkoutActivityType activityType,
- DateTime start,
- DateTime end, {
- int? totalEnergyBurned,
- HealthDataUnit totalEnergyBurnedUnit = HealthDataUnit.KILOCALORIE,
- int? totalDistance,
- HealthDataUnit totalDistanceUnit = HealthDataUnit.METER,
Write workout data to Apple Health
Returns true if successfully added workout data.
Parameters:
activityTypeThe type of activity performedstartThe start time of the workoutendThe end time of the workouttotalEnergyBurnedThe total energy burned during the workouttotalEnergyBurnedUnitThe UNIT used to measuretotalEnergyBurnedONLY FOR IOS Default value is KILOCALORIE.totalDistanceThe total distance traveled during the workouttotalDistanceUnitThe UNIT used to measuretotalDistanceONLY FOR IOS Default value is METER.
Implementation
Future<bool> writeWorkoutData(
HealthWorkoutActivityType activityType,
DateTime start,
DateTime end, {
int? totalEnergyBurned,
HealthDataUnit totalEnergyBurnedUnit = HealthDataUnit.KILOCALORIE,
int? totalDistance,
HealthDataUnit totalDistanceUnit = HealthDataUnit.METER,
}) async {
// Check that value is on the current Platform
if (_platformType == PlatformType.IOS && !_isOnIOS(activityType)) {
throw HealthException(activityType,
"Workout activity type $activityType is not supported on iOS");
} else if (_platformType == PlatformType.ANDROID &&
!_isOnAndroid(activityType)) {
throw HealthException(activityType,
"Workout activity type $activityType is not supported on Android");
}
final args = <String, dynamic>{
'activityType': activityType.name,
'startTime': start.millisecondsSinceEpoch,
'endTime': end.millisecondsSinceEpoch,
'totalEnergyBurned': totalEnergyBurned,
'totalEnergyBurnedUnit': totalEnergyBurnedUnit.name,
'totalDistance': totalDistance,
'totalDistanceUnit': totalDistanceUnit.name,
};
final success = await _channel.invokeMethod('writeWorkoutData', args);
return success ?? false;
}