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
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