NegativeValidator<T extends num> class

A validator that ensures a given num value is negative.

The NegativeValidator checks whether the provided value is strictly less than zero. If the value is valid, the validation passes (null is returned). Otherwise, it returns the provided error message.

Example

final validator = NegativeValidator(message: 'Value must be negative');

print(validator.validate(-5));  // null (valid)
print(validator.validate(-0.1)); // null (valid)
print(validator.validate(0));   // 'Value must be negative' (invalid)
print(validator.validate(5));   // 'Value must be negative' (invalid)
print(validator.validate(null)); // 'Value must be negative' (invalid)
Inheritance

Constructors

NegativeValidator({required String message})
Creates a NegativeValidator that ensures values are negative.

Properties

hashCode int
The hash code for this object.
no setterinherited
message String
The error message to be returned when validation fails.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
validate(covariant T value) String?
Validates the provided value.
override

Operators

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