transformJsonListOfMap<T, R> function Null safety

List<T> transformJsonListOfMap<T, R>(
  1. Map<String, dynamic> json,
  2. String key,
  3. T transform(
    1. R
    )
)

Implementation

List<T> transformJsonListOfMap<T, R>(
  Map<String, dynamic> json,
  String key,
  T Function(R) transform,
) {
  final List<dynamic> list = getJsonValue(json, key);

  T mapper(it) {
    try {
      return transform(it as R);
    } on Exception catch (e, _) {
      throw SchemeConsistencyException(
        'Failed to transform value "$it";\ncause: $e',
      );
    }
  }

  return list.isEmpty ? [] : list.map(mapper).toList();
}