getObjectList<T> static method

List<T>? getObjectList<T>(
  1. dynamic source,
  2. T f(
    1. Map v
    )
)

Converts JSON string or JSON map list source to object list.

Implementation

static List<T>? getObjectList<T>(dynamic source, T Function(Map v) f) {
  if (source == null || source.toString().isEmpty) return null;
  try {
    List list;
    if (source is String) {
      list = json.decode(source);
    } else {
      list = source;
    }
    return list.map((value) {
      if (value is String) {
        value = json.decode(value);
      }
      return f(value);
    }).toList();
  } catch (e) {
    print('JsonUtil convert error, Exception:${e.toString()}');
  }
  return null;
}