Abstract base for all validation types.
The pipeline executes in three phases:
- Pre-processing — transforms that clean or normalize the value
(e.g.,
trim,toLowerCase). Always runs before validation. - Validation — validators that check constraints on the value
(e.g.,
email,min,max). Collects all errors. - Post-processing — transforms that modify the validated value. Only runs if validation passes.
final schema = V.string()
..trim() // phase 1: pre-processing
..email(); // phase 2: validation
See also:
- Implementers
- Available extensions
Properties
- coercer ↔ T Function(Object value)?
-
Optional coercion function to convert input to the expected type.
getter/setter pair
- defaultValueOrNull → T?
-
The configured default value, or
nullwhen none was set. Check hasDefault first to distinguish "no default" fromdefaultValue(null)(which is nonsensical but allowed by the type).no setter - hasAsync → bool
-
Returns
trueif the pipeline contains any async step. Whentrue, the synchronous consumers (parse,validate,safeParse,errors) throw VAsyncRequiredException and the caller must use the*Asyncvariants instead.no setter - hasDefault → bool
-
Returns
trueif a default value was configured via defaultValue. Whentrue, defaultValueOrNull holds the configured value.no setter - hashCode → int
-
The hash code for this object.
no setterinherited
- hasPreprocessors → bool
-
Returns
trueif at least one preprocessor (sync or async) was registered via preprocess / preprocessAsync. Useful for consumers that want to short-circuit a snapshot/preprocess step when there is nothing to run — e.g.valiform's per-field validator only mounts the container preprocess closure when this istrue.no setter - isNullable → bool
-
Returns
trueifnullis accepted by this schema (set via nullable).no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- typeName → String
-
Type-specific prefix used to build error codes for
requiredandinvalid_type. Concrete subclasses return literals like'string','int','bool'. Wrappers delegate to the inner schema.no setter
Methods
-
add(
Validator< T> validator, {String? message, List<Object> ? path, Set<String> ? dependsOn}) → VType<T> - Adds a Validator to the validation phase of the pipeline.
-
addAsync(
AsyncValidator< T> validator, {String? message, List<Object> ? path, Set<String> ? dependsOn}) → VType<T> - Adds an AsyncValidator to the validation phase.
-
addRaw(
Validator< T> validator, {String? message, List<Object> ? path}) → VType<T> -
Adds a Validator that runs in the raw validation phase —
before any per-field iteration in container schemas (VMap /
VObject). The callback inside
validatorsees the input as it arrived (after container preprocess and type check), not the post-pipeline parsed value that add sees. -
applyIf(
bool condition, V builder(V schema)) → V -
Available on V, provided by the VTypeApplyIf extension
Returnsbuilder(this)whenconditionistrue; returnsthisunchanged otherwise. -
defaultValue(
T value) → VType< T> -
Sets a default value to use when the input is
null. -
errors(
Object? value) → List< VError> ? -
Returns the list of VErrors for
value, ornullif valid. -
errorsAsync(
Object? value) → Future< List< VError> ?> -
Async variant of errors. Returns the list of errors, or
nullwhen valid. -
mapType<
R> (R fn< U>(VType< ) → RU> type) - Maps this type through a generic function, preserving the inner type.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
nullable(
) → VType< T> -
Marks this schema as nullable, allowing
nullto pass validation. -
parse(
Object? value) → T? -
Parses
valueand returns the result, or throws a VException on failure. -
parseAsync(
Object? value) → Future< T?> - Async variant of parse. Throws VException on failure.
-
preprocess(
Object? fn(Object? value)) → VType< T> - Applies a function to the raw input before type checking.
-
preprocessAsync(
Future< Object?> fn(Object? value)) → VType<T> - Async variant of preprocess. The function can return a Future — the raw input is transformed before type checking.
-
refine(
bool check(T value), {String? message, String? code, Set< String> ? dependsOn}) → VType<T> - Adds a custom validation check.
-
refineAsync(
Future< bool> check(T value), {String? message, String? code, Duration? timeout, Set<String> ? dependsOn}) → VType<T> - Adds an async custom validation check.
-
runPreprocessors(
Object? value) → Object? -
Runs the synchronous preprocessor chain registered via preprocess
against
valueand returns the result. Does NOT run_resolveNull, validators, or transforms — only the preprocess stage. -
runPreprocessorsAsync(
Object? value) → Future< Object?> - Async variant of runPreprocessors: runs sync preprocessors first, then async preprocessors, in the order they were registered.
-
safeParse(
Object? value) → VResult< T?> -
Parses
valueand returns a VResult without throwing. -
safeParseAsync(
Object? value) → Future< VResult< T?> > -
Async variant of safeParse. Use this when the schema has async
validators (added via
refineAsync). -
toString(
) → String -
A string representation of this object.
inherited
-
transform<
O> (O fn(T value)) → VTransformed< T, O> -
Creates a VTransformed that converts the validated value to type
O. -
transformAsync<
O> (Future< O> fn(T value)) → VTransformedAsync<T, O> - Async variant of transform. The transform function returns a Future — the schema becomes async-only.
-
validate(
Object? value) → bool -
Returns
trueifvaluepasses all validations. -
validateAsync(
Object? value) → Future< bool> -
Async variant of validate. Returns
trueif the value passes.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited