listFromJson<T extends SchemaItem> function

List<T>? listFromJson<T extends SchemaItem>(
  1. dynamic json
)

Converts a JSON list to a nullable-list of SchemaItem instances of type T.

Implementation

List<T>? listFromJson<T extends SchemaItem>(dynamic json) {
  if (json == null) {
    return null;
  }

  if (json is! List) {
    throw ArgumentError.value(json, 'json', 'is not a List');
  }

  return json.map((itemJson) {
    final item = vyuh.content.fromJson<T>(itemJson);
    assert(
        item != null,
        _missingTypeRegistrationMessage<T>(
            vyuh.content.provider.schemaType(itemJson)));

    return item!;
  }).toList(growable: false);
}