NavigationGroup.fromJson constructor

NavigationGroup.fromJson(
  1. Map<String, dynamic> json,
  2. String path
)

Implementation

factory NavigationGroup.fromJson(Map<String, dynamic> json, String path) {
  final keys = opt<List<dynamic>>(json, 'resources') ?? const [];
  return NavigationGroup(
    group: req<String>(json, 'group', path),
    // Not whereType<String>(): dropping a malformed entry makes a navigation
    // item vanish with no diagnostic, which is the same silent hole as an
    // unparsed resource.
    resources: List.generate(keys.length, (index) {
      final key = keys[index];
      if (key is! String) {
        throw SchemaFormatException(
          '$path.resources[$index]',
          'expected String, got ${key.runtimeType}',
        );
      }
      return key;
    }, growable: false),
  );
}