getObjectList<T> function

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

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

Implementation

List<T> getObjectList<T>(Object source, T f(Map v)) {
  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) {
      return f(value);
    })?.toList();
  } catch (e) {
    print('JsonUtil convert error, Exception´╝Ü${e.toString()}');
  }
  return null;
}