Lists and tuples
Lists
list(schema) parses every element with the same schema. schema.list() is equivalent.
final names = string().trim().min(2).list();
final List<String> parsed = names.parse([' Ada ', 'Grace']);
print(parsed); // [Ada, Grace]Failed children include their integer index in the issue path. Unchanged typed lists can reuse their input; use List.of(parsed) for an independent outer list.
Length
list(string()).min(1);
list(string()).max(10);
list(string()).length(3);Membership and uniqueness
list(string()).contains('admin');
list(string()).anyOf(['admin', 'editor']);
list(string()).everyOf(['admin', 'editor']);
list(string()).unique();| Check | Requirement |
|---|---|
contains(value) | At least one element equals the value |
anyOf(values) | At least one element belongs to the allowed values |
everyOf(values) | Every element belongs to the allowed values |
unique() | No two elements compare equal |
Checks run on parsed elements and use Dart equality. everyOf() does not require every allowed value to appear. Container equality is not automatically structural.
unwrap()
final names = string().min(2).list();
final element = names.unwrap();
print(element.tryParse('A').isValid); // falseTuples
tuple() assigns a schema to each position and requires the declared length. Output is a heterogeneous list.
final point = tuple([string(), number(), number()]);
print(point.parse(['home', 10, 20])); // [home, 10, 20].and() includes the receiver as the first element.
final pair = string().and([integer()]);
print(pair.parse(['Ada', 28])); // [Ada, 28]variadic()
Repeat the final schema zero or more times after the fixed prefix. The minimum length is one less than the original tuple length.
final row = tuple([string(), number()]).variadic();
print(row.parse(['scores', 10, 20, 30])); // [scores, 10, 20, 30]
print(row.validate(['scores'])); // trueNullable lists and elements
final List<String?> elements = string().nullable().list().parse(['Ada', null]);
final List<String>? collection = string().list().nullable().parse(null);Modifier order determines which value can be null. See nullable values.
