TagValidator<T> class abstract

Base class for all tag validators.

This abstract class provides a foundation for implementing validators that can be used both internally by tag constructors and externally by users for input validation (e.g., with reactive_forms).

Validators return null for valid values and a Map<String, dynamic> containing error information for invalid values.

Example usage:

final validator = RatingValidator();

// Check if a value is valid
final error = validator.validate(150);
if (error != null) {
  print('Validation failed: ${error}');
}

// Validate and throw on error (used internally by tags)
try {
  final value = validator.validateOrThrow(150);
} on ArgumentError catch (e) {
  print('Invalid rating: ${e.message}');
}

// Use with reactive_forms
final control = FormControl<int>(
  validators: [
    Validators.delegate((c) => validator.validate(c.value)),
  ],
);
Implementers

Constructors

TagValidator()
Creates a new tag validator.
const

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

formatErrorMessage(Map<String, dynamic> error) String
Formats the error map into a human-readable error message.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
validate(T? value) Map<String, dynamic>?
Validates the given value.
validateOrThrow(T value) → T
Validates the value and throws an ArgumentError if invalid.

Operators

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