Button.fromJson constructor

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

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

Implementation

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

  return Button(
    type: ResourceType.fromString(data[ApiFields.type] ?? ""),
    id: data[ApiFields.id] ?? "",
    idV1: data[ApiFields.idV1] ?? "",
    owner: Relative.fromJson(
        Map<String, dynamic>.from(data[ApiFields.owner] ?? {})),
    controlId: Map<String, dynamic>.from(
            data[ApiFields.metadata] ?? {})[ApiFields.controlId] ??
        0,
    lastEvent: Map<String, dynamic>.from(
            data[ApiFields.button] ?? {})[ApiFields.lastEvent] ??
        "",
  );
}