FormControllerMixin mixin
FormControllerMixin is a mixin for any class that needs form validation logic.
It can be used with any state management solution, eg. ChangeNotifier, Riverpod, flutter_bloc, etc.
It can be used to validate the form and to get the validation state of its fields.
The fields can be grouped in subform with using another FormControllerMixin. This will make the form more modular and reusable.
Example:
class UserIdentityFormController with FormControllerMixin {
final email = EmailFieldController();
final password = PasswordFieldController();
List<FormPart> get fields => [email, password];
}
class RegisterFormController with FormControllerMixin {
final userIdentity = UserIdentityFormController();
final firstName = TextFieldController();
final lastName = TextFieldController();
List<FormPart> get fields => [userIdentity, firstName, lastName];
}
- Implemented types
Properties
- debugLabel → String?
-
no setter
-
fields
→ List<
FormPart< FormPartState> > -
The fields of the form.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- value → FormControllerState
-
Current state of the form.
no setteroverride
Methods
-
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object notifies its listeners.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
removeListener(
VoidCallback listener) → void -
Remove a previously registered closure from the list of closures that the
object notifies.
override
-
toMap(
) → Map< String, dynamic> -
Used to dump the state of the node.
override
-
toString(
) → String -
A string representation of this object.
override
-
validate(
{bool? autoValidate}) → bool -
Validates all fields of the form.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited