HealthDataPoint.fromJson constructor
HealthDataPoint.fromJson(
- dynamic json
Converts a json object to the HealthDataPoint
Implementation
factory HealthDataPoint.fromJson(json) {
HealthValue healthValue;
if (json['data_type'] == 'AUDIOGRAM') {
healthValue = AudiogramHealthValue.fromJson(json['value']);
} else if (json['data_type'] == 'WORKOUT') {
healthValue = WorkoutHealthValue.fromJson(json['value']);
} else {
healthValue = NumericHealthValue.fromJson(json['value']);
}
return HealthDataPoint(
healthValue,
HealthDataType.values
.firstWhere((element) => element.name == json['data_type']),
HealthDataUnit.values
.firstWhere((element) => element.name == json['unit']),
DateTime.parse(json['date_from']),
DateTime.parse(json['date_to']),
PlatformTypeJsonValue.keys.toList()[PlatformTypeJsonValue.values
.toList()
.indexOf(json['platform_type'])],
json['device_id'],
json['source_id'],
json['source_name']);
}