ValidatorOptions class

Signature for a function that validates a FlexiCart instance.

Returns a map of field names to error messages if validation fails, or null/empty if validation succeeds. Provides configuration for validating a FlexiCart during its lifecycle, including support for custom validators and promo code validation.

Constructors

ValidatorOptions({List<ICartValidator>? validators, String? promoCode, String? promoCodeValidator(String code)?, bool autoValidate = false})
Creates a new instance of ValidatorOptions.

Properties

autoValidate bool
If true, the cart will be validated automatically after each change.
final
hashCode int
The hash code for this object.
no setterinherited
hasValidators bool
Returns true if at least one validator has been added.
no setter
promoCode String?
The current promotional code applied to the cart, if any.
getter/setter pair
promoCodeValidator String? Function(String code)?
A function that validates the current promoCode.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
validators List<ICartValidator>
A read-only list of validators currently configured.
no setter

Methods

addValidator(ICartValidator validator) → void
Adds a single validator to the list of custom validators.
addValidators(List<ICartValidator> validators) → void
Adds multiple validators to the list at once.
clearValidators() → void
Removes all currently registered validators.
copyWith({List<ICartValidator>? validators, String? promoCode, String? promoCodeValidator(String code)?}) ValidatorOptions
Returns a new ValidatorOptions instance with overridden values.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
removeValidator(ICartValidator validator) → void
Removes the given validator from the list of custom validators.
toMap() Map<String, dynamic>
Convert to Map
toString() String
A string representation of this object.
inherited
validate(FlexiCart<ICartItem> cart) Map<String, dynamic>
Executes all validators and returns a map of validation errors.

Operators

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