transformJsonListOfString<T> function Null safety

List<T> transformJsonListOfString<T>(
  1. Map<String, dynamic> json,
  2. String key
)

Implementation

List<T> transformJsonListOfString<T>(
  Map<String, dynamic> json,
  String key,
) {
  final List<dynamic> list = getJsonValue(json, key);

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

  return list.isEmpty ? [] : list.map(mapper).toList() as List<T>;
}