FormField<R, T, E> class abstract

A container for a single form field that can be validated.

The rawValue property is the raw input of the form field, usually a String. The value property is the parsed value of the field, and will be of type T.

Calling the validate method will validate the field and return an error of type E if the field is invalid. If the field is valid, it will return null.

enum UsernameValidationError { empty, invalid }

class UsernameField
  extends FormField<String, String, UsernameValidationError> {
  const UsernameField({
    required String rawValue,
    this.isRequired = true,
  }) : super(rawValue);

  @override
  String get value => rawValue;

  final bool isRequired;

  @override
  UsernameValidationError? validate() {
    if (rawValue.isEmpty) {
      return UsernameValidationError.empty;
    } else if (!RegExp(r'^[a-zA-Z0-9]+$').hasMatch(rawValue)) {
      return UsernameValidationError.invalid;
    } else {
      return null;
    }
  }
}

{@endtemplate}

Constructors

FormField(R rawValue)
const

Properties

hashCode int
The hash code for this object.
no setterinherited
rawValue → R
The raw value of the field, usually a String.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
value → T
The parsed value of this field.
no setter

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() → E?
Validates the current value of this field.

Operators

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