DecimalValidator class
A validator that ensures a given double value is a decimal (non-integer).
The DecimalValidator checks if a given double value is not a whole number.
If the value has a fractional part, the validation passes (null is returned).
Otherwise, it returns the provided error message.
Example
final validator = DecimalValidator(message: 'The number must be a decimal');
print(validator.validate(3.14)); // null (valid)
print(validator.validate(10.5)); // null (valid)
print(validator.validate(4.0)); // 'The number must be a decimal' (invalid)
print(validator.validate(null)); // 'The number must be a decimal' (invalid)
- Inheritance
-
- Object
- Validator<
double> - ValidatorWithMessage<
double> - DecimalValidator
Constructors
- DecimalValidator({required String message})
-
Creates a
DecimalValidatorwith 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