ResultFormat class abstract
Validation format for form step results.
Provides 35+ built-in validators via factory constructors, plus ResultFormat.compose for chaining multiple validators.
// Built-in validators
ResultFormat.email("Invalid email")
ResultFormat.range("Must be 1-10", 1, 10)
ResultFormat.pattern("Letters only", r'^[a-zA-Z]+$')
// Compose multiple validators
ResultFormat.compose([
ResultFormat.minLength("Too short", 3),
ResultFormat.maxLength("Too long", 50),
])
- Implementers
Constructors
- ResultFormat()
-
Public constructor for creating custom ResultFormat subclasses.
const
- ResultFormat.age(String errorMsg)
-
Requires an integer between 0 and 150.
factory
-
ResultFormat.compose(List<
ResultFormat> validators) -
Applies
validatorsin order and reports the first failure.factory - ResultFormat.consent(String errorMsg)
-
Requires the consent checkbox to be ticked.
factory
- ResultFormat.creditCard(String errorMsg)
-
Requires a 13-19 digit card number that passes the Luhn checksum.
factory
- ResultFormat.custom(String errorMsg, bool validator(String))
-
Validates with your own predicate over the string form of the answer.
factory
- ResultFormat.date(String errorMsg, String format)
-
Requires a DateTime.
formatis the pattern used when exporting it.factory - ResultFormat.dateRange(String errorMsg, String format, {DateTime? minDate, DateTime? maxDate})
-
Requires a DateTime within
minDateandmaxDate, either of which may be null for an open bound.factory - ResultFormat.email(String errorMsg)
-
Requires a syntactically valid email address.
factory
- ResultFormat.expression(String expression)
-
Validates against the FormStack expression grammar. See ExpressionLanguage.
factory
- ResultFormat.fileSize(String errorMsg, int maxBytes)
-
Requires a picked file no larger than
maxBytes.factory - ResultFormat.iban(String errorMsg)
-
Requires an IBAN that passes the mod-97 checksum.
factory
- ResultFormat.length(String errorMsg, int count)
-
Requires a string of exactly
countcharacters — PINs, fixed-width codes.factory - ResultFormat.location(String errorMsg)
-
Requires a location to have been picked.
factory
- ResultFormat.max(String errorMsg, num max)
-
Requires a number less than or equal to
max.factory - ResultFormat.maxLength(String errorMsg, int max)
-
Requires a string of at most
maxcharacters.factory - ResultFormat.maxSelections(String errorMsg, int max)
-
Requires at most
maxoptions to be selected.factory - ResultFormat.min(String errorMsg, num min)
-
Requires a number greater than or equal to
min.factory - ResultFormat.minLength(String errorMsg, int min)
-
Requires a string of at least
mincharacters.factory - ResultFormat.minSelections(String errorMsg, int min)
-
Requires at least
minoptions to be selected.factory - ResultFormat.multipleChoice(String errorMsg)
-
Requires at least one option to be selected.
factory
- ResultFormat.name(String errorMsg)
-
Requires two or more characters, letters and spaces only.
factory
- ResultFormat.none()
-
Accepts anything. Use for steps that collect data but impose no rule.
factory
- ResultFormat.notBlank(String errorMsg)
-
Requires a string with at least one non-whitespace character.
factory
- ResultFormat.notEmpty(String errorMsg)
-
Requires a non-empty String, Iterable or Map.
factory
- ResultFormat.notNull(String errorMsg)
-
Requires any non-null value. The weakest "answer this" rule.
factory
- ResultFormat.number(String errorMsg)
-
Requires a string of digits.
factory
- ResultFormat.password(String errorMsg)
-
Requires 8+ characters with upper, lower, digit and symbol.
factory
- ResultFormat.pattern(String errorMsg, String regex)
-
Requires the answer to match
regex. The pattern is compiled once.factory - ResultFormat.percentage(String errorMsg)
-
Requires a number between 0 and 100.
factory
- ResultFormat.phone(String errorMsg)
-
Requires an E.164-shaped phone number, for example
+14155552671.factory - ResultFormat.range(String errorMsg, num min, num max)
-
Requires a number within
minandmax, both inclusive.factory - ResultFormat.singleChoice(String errorMsg)
-
Requires exactly one option to be selected.
factory
- ResultFormat.smile(String errorMsg)
-
Requires a satisfaction rating to have been chosen.
factory
- ResultFormat.ssn(String errorMsg)
-
Requires a US Social Security Number, with or without dashes.
factory
- ResultFormat.text(String errorMsg)
-
Requires a non-empty string.
factory
- ResultFormat.url(String errorMsg)
-
Requires an
httporhttpsURL.factory - ResultFormat.zipCode(String errorMsg)
-
Requires a US ZIP code, five digits or ZIP+4.
factory
Properties
- code → String
-
Stable machine-readable identifier for this constraint.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
-
params
→ Map<
String, Object?> -
Constraint parameters surfaced on failure, for message interpolation.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
error(
) → String - Human-readable message shown when isValid returns false.
-
isValid(
dynamic input) → bool -
Whether
inputsatisfies this constraint. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
validate(
dynamic input) → ValidationResult -
Validates
input, returning the reason for failure alongside the verdict.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
fromJson(
Object? spec) → ResultFormat? - Builds a validator from its JSON description.
-
register(
String name, ResultFormatFactory factory) → void -
Registers a named validator so
"type": "<name>"can be used in JSON forms. See ValidatorRegistry.