items property

Schema? get items

The schema for all the items in this list, or all those after prefixItems (if present).

For example, to define a schema for a list where all items must be strings:

final schema = ListSchema(items: Schema.string());

In this schema, a list like ['apple', 'banana', 'cherry'] would be valid, but ['apple', 42, 'cherry'] would be invalid because it contains a non-string item.

Note that if you want to define a schema for a list where the initial items have specific types and the remaining items follow a different schema, you can use the prefixItems property in conjunction with items. For example, to allow a string followed by an integer, and then any number of booleans:

final schema = ListSchema(
  prefixItems: [Schema.string(), Schema.int()],
  items: Schema.bool(),
);

Implementation

Schema? get items => _value['items'] as Schema?;