getObject<T> static method

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

Converts JSON string or JSON map source to object.

Implementation

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