prefixItems property
The schema for the initial items in this list, if specified.
For example, to define a schema for a list where the first item must be a string and the second item must be an integer:
final schema = ListSchema(
prefixItems: [Schema.string(), Schema.int()],
);
In this schema, a list like ['hello', 42]
would be valid, but
[42, 'hello']
or ['hello']
would be invalid because they do not
conform to the specified order and types of the prefix items.
Note that if you want to allow additional items in the list that do not
match the prefix items, you can use the items
property to define a
schema for those additional items. For example, to allow any number of
additional strings after the initial string and integer:
final schema = ListSchema(
prefixItems: [Schema.string(), Schema.int()],
items: Schema.string()
);
Implementation
List<Schema>? get prefixItems =>
(_value['prefixItems'] as List?)?.cast<Schema>();