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:
activityType
The type of activity performedstart
The start time of the workoutend
The end time of the workouttotalEnergyBurned
The total energy burned during the workouttotalEnergyBurnedUnit
The UNIT used to measuretotalEnergyBurned
ONLY FOR IOS Default value is KILOCALORIE.totalDistance
The total distance traveled during the workouttotalDistanceUnit
The UNIT used to measuretotalDistance
ONLY 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;
}