extractDataList static method

List<Map<String, dynamic>>? extractDataList(
  1. Map<String, dynamic> dataMap
)

Used to extract the desired data from a raw JSON data map response.

Returns null if the desired list can not be extracted.

Example

/// Raw response
{
  "errors": [],
  "data":
  [
    {
      "id": ...
      ...
    },
    {
      "id2": ...
      ...
    }
  ]
}

/// Desired JSON data
[
  {
    "id": ...
    ...
  },
  {
    "id2": ...
    ...
  }
]

Implementation

static List<Map<String, dynamic>>? extractDataList(
    Map<String, dynamic> dataMap) {
  if (dataMap[ApiFields.data] != null && dataMap[ApiFields.id] == null) {
    try {
      return List<Map<String, dynamic>>.from(dataMap[ApiFields.data]);
    } catch (_) {
      return null;
    }
  }

  return null;
}