ValidationRule class

Represents a single validation rule that can be applied to a string value.

Contains:

  • validate: A function performing the actual validation.
  • errorMessage: The error message returned when validation fails.

The call method executes the validation function and returns errorMessage if validation fails, or null if validation succeeds.

Example usage:

final rule = ValidationRule(
  (value) => value != null && value.isNotEmpty ? null : 'Cannot be empty',
  'Cannot be empty',
);

final result = rule(''); // result is 'Cannot be empty'
final result2 = rule('valid'); // result2 is null

Constructors

ValidationRule(ValidationFunction validate, String errorMessage)
Creates a ValidationRule with the given validate function and errorMessage.
const

Properties

errorMessage String
The error message to return if the validation fails.
final
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
validate ValidationFunction
The validation function to run on the input value.
final

Methods

call(String? value) String?
Executes the validation function on value.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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