GenericBuilder<T> class
Generic builder that supports all validation methods.
Use this builder when you need to apply validations that don't fit into the specialized builders, or when working with dynamic types.
Usage Examples:
// Dynamic type validation
final dynamicValidator = v().type<dynamic>()
.lengthMin(1)
.matches(r'some_pattern')
.build();
// Custom type validation
final customValidator = v().type<MyClass>()
.add(myCustomValidator)
.build();
// Advanced chaining with type coercion
final complexValidator = v().type()
.toString_()
.lengthMin(5)
.email()
.build();
- Inheritance
-
- Object
- IValidator
- BaseBuilder<
GenericBuilder< T> , T> - GenericBuilder
- Mixed-in types
-
- NumberMixin<
GenericBuilder< T> , T> - LengthMixin<
GenericBuilder< T> , T> - EmptyMixin<
GenericBuilder< T> , T> - ComparisonMixin<
GenericBuilder< T> , T> - TransformerMixin<
GenericBuilder< T> , T> - StringMixin<
GenericBuilder< T> , T> - MapMixin<
GenericBuilder< T> , T> - DateTimeMixin<
GenericBuilder< T> , T> - JsonMixin<
GenericBuilder< T> , T>
- NumberMixin<
- Available extensions
Constructors
- GenericBuilder({Chain? chain})
Properties
- chain → Chain
-
finalinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- isNullable → bool
-
finalinherited
- isOptional → bool
-
finalinherited
- negated ↔ bool
-
getter/setter pairinherited
-
not
→ GenericBuilder<
T> -
Return a negated version of the builder
(the negation flag is consumed by the next added validator)
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
self
→ GenericBuilder<
T> -
no setterinherited
Methods
-
add(
IValidator validator, {String? message}) → GenericBuilder< T> -
Add a validator to the chain.
inherited
-
after(
DateTime dt, {bool inclusive = false, String? message}) → GenericBuilder< T> -
Validate that the DateTime is after the specified date.
inherited
-
before(
DateTime dt, {bool inclusive = false, String? message}) → GenericBuilder< T> -
Validate that the DateTime is before the specified date.
inherited
-
between(
num min, num max, {String? message}) → GenericBuilder< T> -
Validate that the number is within the specified range.
inherited
-
betweenDates(
DateTime start, DateTime end, {bool inclusiveStart = true, bool inclusiveEnd = true, String? message}) → GenericBuilder< T> -
Validate that the DateTime is within the specified date range.
@return The builder for chaining
inherited
-
boolString(
{String? message}) → GenericBuilder< T> -
Validate that the string can be parsed as a boolean.
inherited
-
build(
) → IValidator -
Build resulting validator.
inherited
-
collapseWhitespace(
) → GenericBuilder< T> -
Normalize the string by collapsing multiple whitespace characters into single spaces.
inherited
-
containsKey(
dynamic key, {String? message}) → GenericBuilder< T> -
Validate that the map contains the specified key.
inherited
-
copyWith(
{bool? nullable, bool? optional}) → IValidator -
inherited
-
deepEq(
T value, {String? message}) → GenericBuilder< T> -
Require the value to be deeply equal to the specified value.
inherited
-
doubleString(
{String? message}) → GenericBuilder< T> -
Validate that the string can be parsed as a double.
inherited
-
email(
{String? message}) → GenericBuilder< T> -
Validate that the string is a valid email address.
inherited
-
empty(
{String? message}) → GenericBuilder< T> -
Validate that the value is empty.
inherited
-
eq(
T value, {String? message}) → GenericBuilder< T> -
Require the value to be equal to the specified value.
inherited
-
error(
String message) → GenericBuilder< T> -
Override final error message (retains codes).
inherited
-
flattenKeys(
[String delimiter = '.']) → GenericBuilder< T> -
Flatten nested map keys using the specified delimiter.
inherited
-
gt(
num n, {String? message}) → GenericBuilder< T> -
Validate that the number is greater than the specified value.
inherited
-
gte(
num n, {String? message}) → GenericBuilder< T> -
Validate that the number is greater than or equal to the specified value.
inherited
-
inFuture(
{bool allowNow = true, String? message}) → GenericBuilder< T> -
Validate that the DateTime is in the future.
inherited
-
inPast(
{bool allowNow = true, String? message}) → GenericBuilder< T> -
Validate that the DateTime is in the past.
inherited
-
intString(
{String? message}) → GenericBuilder< T> -
Validate that the string can be parsed as an integer.
inherited
-
isDate(
{String? message}) → GenericBuilder< T> -
Validate that the string is a valid DateTime format.
inherited
-
isNotValid(
dynamic value) → bool -
inherited
-
isNotValidAsync(
dynamic value) → FutureOr< bool> -
inherited
-
isValid(
dynamic value) → bool -
inherited
-
isValidAsync(
dynamic value) → FutureOr< bool> -
inherited
-
jsonArray(
{String? message}) → GenericBuilder< T> -
Validate that the value is a valid JSON array.
inherited
-
jsonArrayEach(
IValidator elementValidator, {String? message}) → GenericBuilder< T> -
Validate that each element in a JSON array satisfies the provided validator.
inherited
-
jsonArrayLen(
{int? min, int? max, String? message}) → GenericBuilder< T> -
Validate the length of a JSON array.
inherited
-
jsonContainer(
{String? message}) → GenericBuilder< T> -
Validate that the value is a valid JSON container (object or array).
inherited
-
jsonObject(
{String? message}) → GenericBuilder< T> -
Validate that the value is a valid JSON object.
inherited
-
jsonRequiresKeys(
Iterable< String> keys, {String? message}) → GenericBuilder<T> -
Validate that the JSON object contains all required keys.
inherited
-
length(
List< IValidator> lengthValidators, {String? message}) → GenericBuilder<T> -
Validate that the length matches all the provided validators.
inherited
-
lengthMax(
int max, {String? message}) → GenericBuilder< T> -
Validate that the length is at most the specified maximum.
inherited
-
lengthMin(
int min, {String? message}) → GenericBuilder< T> -
Validate that the length is at least the specified minimum.
inherited
-
lengthRange(
int min, int max, {String? message}) → GenericBuilder< T> -
Validate that the length is within the specified range.
inherited
-
lowerCase(
{String? message}) → GenericBuilder< T> -
Validate that the string contains only lowercase characters.
inherited
-
lt(
num n, {String? message}) → GenericBuilder< T> -
Validate that the number is less than the specified value.
inherited
-
lte(
num n, {String? message}) → GenericBuilder< T> -
Validate that the number is less than or equal to the specified value.
inherited
-
matches(
RegExp pattern, {String? message}) → GenericBuilder< T> -
Validate that the string matches the provided regular expression pattern.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
nullable<
_> ({String? message}) → GenericBuilder< T> -
Mark current chain nullable (null accepted as valid).
inherited
-
numString(
{String? message}) → GenericBuilder< T> -
Validate that the string can be parsed as a number.
inherited
-
oneOf(
Iterable< T> values, {String? message}) → GenericBuilder<T> -
Require the value to be one of the specified options.
inherited
-
optional<
_> () → GenericBuilder< T> -
Mark current chain optional (skipped when key absent).
inherited
-
pick(
Iterable< String> keys) → GenericBuilder<T> -
Extract only the specified keys from the map.
inherited
-
pluck(
String key) → GenericBuilder< T> -
Extract a single key from the map, keeping the map structure.
@return The builder for chaining
inherited
-
pluckValue(
String key) → GenericBuilder -
Extract a single value from the map, returning a GenericBuilder for further operations.
@return A GenericBuilder for the extracted value
inherited
-
sameDay(
DateTime dt, {String? message}) → GenericBuilder< T> -
Validate that the DateTime is on the same day as the specified date.
inherited
-
schema(
Map< String, IValidator> schema) → GenericBuilder<T> -
Validate the map against a schema where keys are optional unless specified.
inherited
-
strict(
Map< String, IValidator> schema) → GenericBuilder<T> -
Validate the map against a strict schema where all keys must be present and match the validators.
inherited
-
strictUrl(
{String? message}) → GenericBuilder< T> -
Validate that the string is a valid URL with strict requirements.
inherited
-
toBigInt(
) → NumberBuilder -
Transform the value to a BigInt.
inherited
-
toBool(
{String? message}) → BoolBuilder -
Transform the value to a boolean using standard parsing.
inherited
-
toBoolLenient(
{String? message}) → BoolBuilder -
Transform the value to a boolean using lenient parsing.
inherited
-
toBoolStrict(
{String? message}) → BoolBuilder -
Transform the value to a boolean using strict parsing.
inherited
-
toDateTime(
) → DateTimeBuilder -
Transform string to DateTime using standard parsing.
inherited
-
toDouble(
{String? message}) → DoubleBuilder -
Transform the value to a double using standard parsing.
inherited
-
toInt(
{String? message}) → IntBuilder -
Transform the value to an integer using standard parsing.
inherited
-
toIntSafe(
{String? message}) → IntBuilder -
Transform the value to an integer using safe parsing (returns null on failure).
inherited
-
toIntStrict(
{String? message}) → IntBuilder -
Transform the value to an integer using strict parsing (no fallback to 0).
inherited
-
toJson(
) → JsonDecodedBuilder -
Transform JSON string to decoded object (Map/List).
inherited
-
toLowerCase(
) → GenericBuilder< T> -
Convert the string to lowercase.
inherited
-
toNum(
) → NumberBuilder -
Transform the value to a number (int or double).
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
toString_(
{String? message}) → StringBuilder -
Transform the value to a string.
inherited
-
toUpperCase(
) → GenericBuilder< T> -
Convert the string to uppercase.
inherited
-
trim(
) → GenericBuilder< T> -
Normalize the string by trimming whitespace from both ends.
inherited
-
upperCase(
{String? message}) → GenericBuilder< T> -
Validate that the string contains only uppercase characters.
inherited
-
url(
{String? message, bool strict = false}) → GenericBuilder< T> -
Validate that the string is a valid URL.
inherited
-
use(
CustomPivot pivot) → GenericBuilder -
Apply a custom transformation using the provided pivot.
inherited
-
validate(
dynamic value, {bool? exists}) → Result -
Convenience validate (sync only chain).
inherited
-
validateAsync(
dynamic value, {bool? exists}) → Future< Result> -
Convenience validateAsync (mixed / async).
inherited
-
validateOrThrow(
dynamic value) → Result -
inherited
-
validator(
dynamic value) → FutureOr< Result> -
inherited
-
wrap(
IValidator fn(IValidator), {String? message}) → GenericBuilder< T> -
Wrap the current chain with a custom function.
inherited
Operators
-
operator &(
IValidator other) → IValidator -
Available on IValidator, provided by the EskemaEskValidatorOperations extension
Combines two validators with a logical AND, same as using all -
operator ==(
Object other) → bool -
The equality operator.
inherited
-
operator >(
Expectation error) → IValidator -
Available on IValidator, provided by the EskemaEskValidatorOperations extension
Returns a new validator that will return theerrormessage if the validation fails -
operator |(
IValidator other) → IValidator -
Available on IValidator, provided by the EskemaEskValidatorOperations extension
Combines two validators with a logical OR, same as using any