CurrentFieldValidation<T> class

Tracks validation metadata for a single CurrentProperty.

This helper is intended to be owned by a CurrentViewModel alongside the property it validates. It stores a list of CurrentValidationRule objects, exposes the current state, and can optionally re-run validation whenever the underlying property value changes.

Validation metadata is sent through the Current event stream by sending CurrentValidationChanged events. This means widgets using a CurrentViewModel can react to validation changes automatically.

Example

class ProfileViewModel extends CurrentViewModel {
  final email = CurrentStringProperty('', propertyName: 'email');

  CurrentFieldValidation<String>? _emailValidation;
  CurrentFieldValidation<String> get emailValidation =>
      _emailValidation ??= email.createValidation(
    rules: [
      (value) => value.isEmpty
          ? const CurrentValidationIssue(
              'profile.email.required',
              fallbackMessage: 'Email is required',
            )
          : null,
      (value) => value.contains('@')
          ? null
          : const CurrentValidationIssue(
              'profile.email.invalid',
              fallbackMessage: 'Email is invalid',
            ),
    ],
    validateOnPropertyChange: true,
  );

  @override
  Iterable<CurrentProperty> get currentProps => [email];
}
Implemented types

Constructors

CurrentFieldValidation(CurrentProperty<T> property, {Iterable<CurrentValidationRule<T>> rules = const [], bool validateOnPropertyChange = false})
Creates a validator for the provided property.

Properties

hashCode int
The hash code for this object.
no setterinherited
hasIssue bool
Whether the validator currently has an issue.
no setter
hasValidated bool
Whether validation has run at least once.
no setter
issue CurrentValidationIssue?
The current validation issue, if any.
no setter
isTouched bool
Whether the field has been marked as touched.
no setter
isValid bool
Whether the current validation state is valid.
no setter
property CurrentProperty<T>
The property whose value this validator describes.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
state CurrentValidationState
The current validation state.
no setter
validateOnPropertyChange bool
Whether validation should automatically re-run when property changes.
final
validationSourceHashCode int
Unique identifier for this validation instance.
final

Methods

addRule(CurrentValidationRule<T> rule) CurrentFieldValidation<T>
Adds a validation rule to this validator.
attachToViewModel() → void
Attaches this validator to the owning CurrentViewModel.
override
issueForValue(T value) CurrentValidationIssue?
Evaluates the configured rules against value without mutating state.
markTouched() → void
Marks the field as touched without changing the current error state.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
reset() → void
Resets the validation metadata back to the untouched state.
resolveIssueText({BuildContext? context, CurrentValidationIssueTextResolver? resolver}) String?
Resolves the current issue into display text.
setIssue(CurrentValidationIssue? issue, {bool markTouched = false}) → void
Sets a validation issue manually.
toString() String
A string representation of this object.
inherited
validate({bool markTouched = false}) CurrentValidationState
Runs the validator rules against the current property value.

Operators

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