PrimeValidator class
A validator that checks whether a given integer is a prime number.
A prime number is a natural number greater than 1 that has no divisors other than 1 and itself.
Example
final primeValidator = PrimeValidator(message: 'The number must be prime');
print(primeValidator.validate(2)); // null (valid)
print(primeValidator.validate(13)); // null (valid)
print(primeValidator.validate(4)); // 'The number must be prime' (invalid)
print(primeValidator.validate(9)); // 'The number must be prime' (invalid)
Parameters
- message: Custom error message when validation fails.
- Inheritance
-
- Object
- Validator<
int> - ValidatorWithMessage<
int> - PrimeValidator
Constructors
- PrimeValidator({required String message})
-
Creates a
PrimeValidatorto check if an integer is a prime number.
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 int value) → String? -
Validates the provided
value.override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited