LazyFormix<T, E> class
A validator that defers instantiation until first use.
The validator is only created when validate is called for the first time. Subsequent calls reuse the same instance.
final validator = Validate.lazy(() => Validate.all([
StringRules.required(error: 'Required'),
_buildExpensiveValidator(), // Only created on first validate()
]));
// Validator not yet created
validator.validate('test'); // Now created and cached
validator.validate('test2'); // Reuses same instance
This is useful for:
- Validators with expensive setup/initialization
- Conditional validators that may never be used
- Breaking circular dependencies between validators
- Reducing startup time by deferring validator construction
- Inheritance
- Available extensions
Constructors
-
LazyFormix(Formix<
T, E> _factory()) -
Creates a lazy validator from a
factoryfunction.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- isInstantiated → bool
-
Returns
trueif the validator has been instantiated.no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
validator
→ Formix<
T, E> -
Returns the underlying validator, creating it if necessary.
no setter
Methods
-
andThen(
Formix< T, E> next) → Formix<T, E> -
Available on Formix<
Chains this validator withT, E> , provided by the FormixExtensions extensionnext, runningnextonly if this passes. -
cached(
) → CachedFormix< T, E> -
Available on Formix<
Wraps this validator with single-value caching.T, E> , provided by the FormixExtensions extension -
lazy(
) → LazyFormix< T, E> -
Available on Formix<
Creates a lazy validator that defers instantiation until first use.T, E> , provided by the FormixExtensions extension -
lruCached(
{int maxSize = 10}) → LruCachedFormix< T, E> -
Available on Formix<
Wraps this validator with LRU (Least Recently Used) caching.T, E> , provided by the FormixExtensions extension -
mapError<
E2> (E2 mapper(E error)) → Formix< T, E2> -
Available on Formix<
Maps errors from typeT, E> , provided by the FormixExtensions extensionEto typeE2. -
materialize(
) → void - Forces instantiation of the underlying validator.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
optional(
{bool isEmpty(T value)?}) → Formix< T, E> -
Available on Formix<
Makes this validator optional - skips validation when empty.T, E> , provided by the FormixExtensions extension -
recover(
T onError(List< E> errors)) → Formix<T, E> -
Available on Formix<
Recovers from validation errors with a default value.T, E> , provided by the FormixExtensions extension -
reset(
) → void - Resets the lazy validator, allowing the factory to be called again.
-
tap(
{void onValid(T value)?, void onInvalid(List< E> errors)?}) → Formix<T, E> -
Available on Formix<
Applies side effects without affecting validation.T, E> , provided by the FormixExtensions extension -
toString(
) → String -
A string representation of this object.
inherited
-
validate(
T value) → ValidationResult< T, E> -
Validates
valueand returns a ValidationResult.override -
when(
bool condition(T value)) → Formix< T, E> -
Available on Formix<
Conditionally applies this validator based onT, E> , provided by the FormixExtensions extensioncondition. -
whenNot(
bool condition(T value)) → Formix< T, E> -
Available on Formix<
Conditionally skips this validator based onT, E> , provided by the FormixExtensions extensioncondition. -
withMessageFormatter(
ErrorMessageFormatter< E> formatter) → Formix<T, String> -
Available on Formix<
Maps errors to user-facing messages usingT, E> , provided by the FormixExtensions extensionformatter.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited