fromArgument function

Object? fromArgument(
  1. HealthResource resource,
  2. String argument
)

Implementation

Object? fromArgument(HealthResource resource, String argument) {
  switch (resource) {
    case HealthResource.activity:
      return (jsonDecode(argument) as List)
          .map((e) => ActivitySummary.fromJson(e))
          .toList();
    case HealthResource.profile:
      return ProfileSummary.fromJson(jsonDecode(argument));
    case HealthResource.body:
      return BodySummary.fromJson(jsonDecode(argument));
    case HealthResource.sleep:
      return (jsonDecode(argument) as List)
          .map((e) => SleepSummary.fromJson(e))
          .toList();
    case HealthResource.workout:
      return (jsonDecode(argument) as List)
          .map((e) => WorkoutSummary.fromJson(e))
          .toList();
    case HealthResource.glucose:
      return (jsonDecode(argument) as List)
          .map((e) => QuantitySample.fromJson(e))
          .toList();
    case HealthResource.bloodPressure:
      return (jsonDecode(argument) as List)
          .map((e) => BloodPressureSample.fromJson(e))
          .toList();
    case HealthResource.heartRate:
      return (jsonDecode(argument) as List)
          .map((e) => QuantitySample.fromJson(e))
          .toList();
    case HealthResource.water:
      return (jsonDecode(argument) as List)
          .map((e) => QuantitySample.fromJson(e))
          .toList();
    case HealthResource.caffeine:
      return (jsonDecode(argument) as List)
          .map((e) => QuantitySample.fromJson(e))
          .toList();
    default:
      return null;
  }
}