Workout.fromJson constructor

Workout.fromJson(
  1. Map<String, dynamic> json
)

Implementation

factory Workout.fromJson(Map<String, dynamic> json) {
  return Workout(
    uuid: json['uuid'] as String,
    start: DateTime.fromMillisecondsSinceEpoch(
      ((json['startTimestamp'] as double) * 1000).toInt(),
    ),
    end: DateTime.fromMillisecondsSinceEpoch(
      ((json['endTimestamp'] as double) * 1000).toInt(),
    ),
    sourceRevision: SourceRevision.fromJson(Map.from(json['sourceRevision'])),
    device: json['device'] != null
        ? Device.fromJson(Map.from(json['device']))
        : null,
    workoutActivityType: WorkoutActivityType.values.firstWhereOrNull(
          (e) => e.code == json['workoutActivityType'],
        ) ??
        WorkoutActivityType.other,
    metadata: json['metadata'] != null ? Map.from(json['metadata']) : null,
    duration: Duration(seconds: (json['duration'] as double).toInt()),
  );
}