VLiteral<T> class
Validates that a value is exactly equal to the expected literal.
final schema = V.literal('active');
schema.parse('active'); // 'active'
schema.parse('inactive'); // throws VException
- Inheritance
- Available extensions
Constructors
Properties
- coercer ↔ T Function(Object value)?
-
Optional coercion function to convert input to the expected type.
getter/setter pairinherited
- 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 setterinherited - 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 setterinherited - hasDefault → bool
-
Returns
trueif a default value was configured via defaultValue. Whentrue, defaultValueOrNull holds the configured value.no setterinherited - 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 setterinherited - isNullable → bool
-
Returns
trueifnullis accepted by this schema (set via nullable).no setterinherited - 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 setteroverride
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.
inherited
-
addAsync(
AsyncValidator< T> validator, {String? message, List<Object> ? path, Set<String> ? dependsOn}) → VType<T> -
Adds an AsyncValidator to the validation phase.
inherited
-
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 insidevalidatorsees the input as it arrived (after container preprocess and type check), not the post-pipeline parsed value that add sees.inherited -
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.inherited -
errors(
Object? value) → List< VError> ? -
Returns the list of VErrors for
value, ornullif valid.inherited -
errorsAsync(
Object? value) → Future< List< VError> ?> -
Async variant of errors. Returns the list of errors, or
nullwhen valid.inherited -
mapType<
R> (R fn< U>(VType< ) → RU> type) -
Maps this type through a generic function, preserving the inner type.
inherited
-
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.inherited -
parse(
Object? value) → T? -
Parses
valueand returns the result, or throws a VException on failure.inherited -
parseAsync(
Object? value) → Future< T?> -
Async variant of parse. Throws VException on failure.
inherited
-
preprocess(
Object? fn(Object? value)) → VType< T> -
Applies a function to the raw input before type checking.
inherited
-
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.
inherited
-
refine(
bool check(T value), {String? message, String? code, Set< String> ? dependsOn}) → VType<T> -
Adds a custom validation check.
inherited
-
refineAsync(
Future< bool> check(T value), {String? message, String? code, Duration? timeout, Set<String> ? dependsOn}) → VType<T> -
Adds an async custom validation check.
inherited
-
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.inherited -
runPreprocessorsAsync(
Object? value) → Future< Object?> -
Async variant of runPreprocessors: runs sync preprocessors first,
then async preprocessors, in the order they were registered.
inherited
-
safeParse(
Object? value) → VResult< T?> -
Parses
valueand returns a VResult without throwing.override -
safeParseAsync(
Object? value) → Future< VResult< T?> > -
Async variant of safeParse. Use this when the schema has async
validators (added via
refineAsync).inherited -
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.inherited -
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.
inherited
-
validate(
Object? value) → bool -
Returns
trueifvaluepasses all validations.inherited -
validateAsync(
Object? value) → Future< bool> -
Async variant of validate. Returns
trueif the value passes.inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited