Motion.fromJson constructor

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

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

Implementation

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

  Map<String, dynamic> innerMotionMap =
      Map<String, dynamic>.from(data[ApiFields.motion]);

  return Motion(
    type: ResourceType.fromString(data[ApiFields.type] ?? ""),
    id: data[ApiFields.id] ?? "",
    idV1: data[ApiFields.idV1] ?? "",
    owner: Relative.fromJson(
        Map<String, dynamic>.from(data[ApiFields.owner] ?? {})),
    isEnabled: data[ApiFields.isEnabled] ?? false,
    hasMotion: innerMotionMap[ApiFields.motion] ?? false,
    isValidMotion: innerMotionMap[ApiFields.motionValid] ?? false,
  );
}