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

Constructors

PrimeValidator({required String message})
Creates a PrimeValidator to check if an integer is a prime number.

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 int value) String?
Validates the provided value.
override

Operators

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