factory static method
Factory method to create the sample its type discriminator names.
Throws an InvalidValueException for an unknown type,
so no sample is dropped silently.
Implementation
static Sample factory(Map<String, dynamic> json) {
final type = json['type'];
final healthType =
type is String ? HealthType.tryFromIdentifier(type) : null;
switch (healthType) {
case HealthType.activeCaloriesBurned:
return ActiveCaloriesBurned.fromJson(json);
case HealthType.basalBodyTemperature:
return BasalBodyTemperature.fromJson(json);
case HealthType.basalMetabolicRate:
return BasalMetabolicRate.fromJson(json);
case HealthType.bloodGlucose:
return BloodGlucose.fromJson(json);
case HealthType.bloodPressure:
return BloodPressure.fromJson(json);
case HealthType.bodyFat:
return BodyFat.fromJson(json);
case HealthType.bodyTemperature:
return BodyTemperature.fromJson(json);
case HealthType.bodyWaterMass:
return BodyWaterMass.fromJson(json);
case HealthType.boneMass:
return BoneMass.fromJson(json);
case HealthType.cervicalMucus:
return CervicalMucus.fromJson(json);
case HealthType.cyclingPedalingCadence:
return CyclingPedalingCadence.fromJson(json);
case HealthType.distance:
return Distance.fromJson(json);
case HealthType.elevationGained:
return ElevationGained.fromJson(json);
case HealthType.exerciseSession:
return ExerciseSession.fromJson(json);
case HealthType.floorsClimbed:
return FloorsClimbed.fromJson(json);
case HealthType.heartRate:
return HeartRate.fromJson(json);
case HealthType.heartRateVariabilityRmssd:
return HeartRateVariabilityRmssd.fromJson(json);
case HealthType.height:
return Height.fromJson(json);
case HealthType.hydration:
return Hydration.fromJson(json);
case HealthType.intermenstrualBleeding:
return IntermenstrualBleeding.fromJson(json);
case HealthType.leanBodyMass:
return LeanBodyMass.fromJson(json);
case HealthType.menstruationFlow:
return MenstruationFlow.fromJson(json);
case HealthType.menstruationPeriod:
return MenstruationPeriod.fromJson(json);
case HealthType.mindfulnessSession:
return MindfulnessSession.fromJson(json);
case HealthType.nutrition:
return Nutrition.fromJson(json);
case HealthType.ovulationTest:
return OvulationTest.fromJson(json);
case HealthType.oxygenSaturation:
return OxygenSaturation.fromJson(json);
case HealthType.plannedExerciseSession:
return PlannedExerciseSession.fromJson(json);
case HealthType.power:
return Power.fromJson(json);
case HealthType.respiratoryRate:
return RespiratoryRate.fromJson(json);
case HealthType.restingHeartRate:
return RestingHeartRate.fromJson(json);
case HealthType.sexualActivity:
return SexualActivity.fromJson(json);
case HealthType.skinTemperature:
return SkinTemperature.fromJson(json);
case HealthType.sleepSession:
return SleepSession.fromJson(json);
case HealthType.speed:
return Speed.fromJson(json);
case HealthType.steps:
return Steps.fromJson(json);
case HealthType.stepsCadence:
return StepsCadence.fromJson(json);
case HealthType.totalCaloriesBurned:
return TotalCaloriesBurned.fromJson(json);
case HealthType.vo2Max:
return Vo2Max.fromJson(json);
case HealthType.weight:
return Weight.fromJson(json);
case HealthType.wheelchairPushes:
return WheelchairPushes.fromJson(json);
case null:
throw InvalidValueException('Unknown sample type: $type');
}
}