factory static method

Sample factory(
  1. Map<String, dynamic> json
)

Factory method to create instances as a result of HealthKitReporter.sampleQuery and HealthKitReporter.anchoredObjectQuery. Throws an InvalidValueException for an identifier it doesn't know, so no sample is dropped silently.

Implementation

static Sample factory(Map<String, dynamic> json) {
  final String identifier = json['identifier'];
  if (QuantityTypeFactory.tryFrom(identifier) != null) {
    return Quantity.fromJson(json);
  }
  if (CategoryTypeFactory.tryFrom(identifier) != null) {
    return Category.fromJson(json);
  }
  if (WorkoutTypeFactory.tryFrom(identifier) != null) {
    return Workout.fromJson(json);
  }
  if (CorrelationTypeFactory.tryFrom(identifier) != null) {
    return Correlation.fromJson(json);
  }
  if (ElectrocardiogramTypeFactory.tryFrom(identifier) != null) {
    return Electrocardiogram.fromJson(json);
  }
  if (ClinicalTypeFactory.tryFrom(identifier) != null) {
    return ClinicalRecord.fromJson(json);
  }
  if (AudiogramTypeFactory.tryFrom(identifier) != null) {
    return Audiogram.fromJson(json);
  }
  if (StateOfMindTypeFactory.tryFrom(identifier) != null) {
    return StateOfMind.fromJson(json);
  }
  if (ScoredAssessmentTypeFactory.tryFrom(identifier) != null) {
    return ScoredAssessment.fromJson(json);
  }
  if (DocumentTypeFactory.tryFrom(identifier) != null) {
    return CDADocument.fromJson(json);
  }
  if (identifier == VisionPrescriptionType.visionPrescription.identifier) {
    return VisionPrescription.fromJson(json);
  }
  if (identifier == MedicationType.medicationDoseEvent.identifier) {
    return MedicationDoseEvent.fromJson(json);
  }
  switch (SeriesTypeFactory.tryFrom(identifier)) {
    case SeriesType.heartbeatSeries:
      return HeartbeatSeries.fromJson(json);
    case SeriesType.workoutRoute:
      return WorkoutRoute.fromJson(json);
    case null:
      throw InvalidValueException('Unknown sample identifier: $identifier');
  }
}