VType<T> class abstract Core

Abstract base for all validation types.

The pipeline executes in three phases:

  1. Pre-processing — transforms that clean or normalize the value (e.g., trim, toLowerCase). Always runs before validation.
  2. Validation — validators that check constraints on the value (e.g., email, min, max). Collects all errors.
  3. 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:

  • V, the entry point that creates every concrete schema.
  • VResult, what the safe-parse family returns.
  • Validator, the extension point for a custom rule.
Implementers
Available extensions

Constructors

VType({String? message, String? invalidTypeMessage})
Creates a VType.

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 null when none was set. Check hasDefault first to distinguish "no default" from defaultValue(null) (which is nonsensical but allowed by the type).
no setter
hasAsync bool
Returns true if the pipeline contains any async step. When true, the synchronous consumers (parse, validate, safeParse, errors) throw VAsyncRequiredException and the caller must use the *Async variants instead.
no setter
hasDefault bool
Returns true if a default value was configured via defaultValue. When true, defaultValueOrNull holds the configured value.
no setter
hashCode int
The hash code for this object.
no setterinherited
hasPreprocessors bool
Returns true if 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 is true.
no setter
isNullable bool
Returns true if null is 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 required and invalid_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 validator sees 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

Returns builder(this) when condition is true; returns this unchanged 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, or null if valid.
errorsAsync(Object? value) Future<List<VError>?>
Async variant of errors. Returns the list of errors, or null when valid.
mapType<R>(R fn<U>(VType<U> type)) → R
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 null to pass validation.
parse(Object? value) → T?
Parses value and 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 value and 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 value and 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 true if value passes all validations.
validateAsync(Object? value) Future<bool>
Async variant of validate. Returns true if the value passes.

Operators

operator ==(Object other) bool
The equality operator.
inherited