Scene.fromJson constructor

Scene.fromJson(
  1. Map<String, dynamic> dataMap
)

Creates a Scene object from the JSON response to a GET request.

Implementation

factory Scene.fromJson(Map<String, dynamic> dataMap) {
  // Handle entire response given with no filter.
  Map<String, dynamic> data = MiscTools.extractData(dataMap);

  return Scene(
    type: ResourceType.fromString(data[ApiFields.type] ?? ""),
    id: data[ApiFields.id] ?? "",
    idV1: data[ApiFields.idV1] ?? "",
    actions: List<SceneAction>.from(
        List<Map<String, dynamic>>.from(data[ApiFields.actions] ?? {})
            .map((actionJson) => SceneAction.fromJson(actionJson))
            .toList()),
    recall: SceneRecall.fromJson(
        Map<String, dynamic>.from(data[ApiFields.recall] ?? {})),
    metadata: SceneMetadata.fromJson(
        Map<String, dynamic>.from(data[ApiFields.metadata] ?? {})),
    group: Relative.fromJson(
        Map<String, dynamic>.from(data[ApiFields.group] ?? {})),
    palette: ScenePalette.fromJson(
        Map<String, dynamic>.from(data[ApiFields.palette] ?? {})),
    speed: ((data[ApiFields.speed] ?? 0.0) as num).toDouble(),
    autoDynamic: data[ApiFields.autoDynamic] ?? false,
  );
}