IntegerValidator class
A validator that ensures a given double
value is an integer.
The IntegerValidator
checks if the provided value is a whole number (i.e., it has no decimal part).
If the value is an integer, validation passes (null
is returned). Otherwise, it returns the provided error message.
Example
final validator = IntegerValidator(message: 'The number must be an integer');
print(validator.validate(10.0)); // null (valid)
print(validator.validate(-5.0)); // null (valid)
print(validator.validate(3.14)); // 'The number must be an integer' (invalid)
print(validator.validate(null)); // 'The number must be an integer' (invalid)
- Inheritance
-
- Object
- Validator<
double> - ValidatorWithMessage<
double> - IntegerValidator
Constructors
- IntegerValidator.new({required String message})
-
Creates an
IntegerValidator
with a required error message.
Properties
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 double value) → String? -
Validates the provided
value
.override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited