writeWorkoutData method
Future<bool>
writeWorkoutData({
- required HealthWorkoutActivityType activityType,
- required DateTime start,
- required DateTime end,
- int? totalEnergyBurned,
- HealthDataUnit totalEnergyBurnedUnit = HealthDataUnit.KILOCALORIE,
- int? totalDistance,
- HealthDataUnit totalDistanceUnit = HealthDataUnit.METER,
- String? title,
Write workout data to Apple Health or Google Fit or Google Health Connect.
Returns true if the workout data was successfully added.
Parameters:
activityType
The type of activity performed.start
The start time of the workout.end
The end time of the workout.totalEnergyBurned
The total energy burned during the workout.totalEnergyBurnedUnit
The UNIT used to measuretotalEnergyBurned
ONLY FOR IOS Default value is KILOCALORIE.totalDistance
The total distance traveled during the workout.totalDistanceUnit
The UNIT used to measuretotalDistance
ONLY FOR IOS Default value is METER.title
The title of the workout. ONLY FOR HEALTH CONNECT Default value is theactivityType
, e.g. "STRENGTH_TRAINING".
Implementation
Future<bool> writeWorkoutData({
required HealthWorkoutActivityType activityType,
required DateTime start,
required DateTime end,
int? totalEnergyBurned,
HealthDataUnit totalEnergyBurnedUnit = HealthDataUnit.KILOCALORIE,
int? totalDistance,
HealthDataUnit totalDistanceUnit = HealthDataUnit.METER,
String? title,
}) async {
// Check that value is on the current Platform
if (Platform.isIOS && !_isOnIOS(activityType)) {
throw HealthException(activityType,
"Workout activity type $activityType is not supported on iOS");
} else if (Platform.isAndroid && !_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,
'title': title,
};
return await _channel.invokeMethod('writeWorkoutData', args) == true;
}