How automatic validation works with FormzMixin
mainYou can create a unified form object (like a LoginForm) by using the FormzMixin. By implementing the inputs getter to return a list of your FormzInput objects, the mixin provides an isValid property for the entire form.
- Create a class representing your form.
- Mix in
FormzMixin. - Override
List<FormzInput> get inputsto return all fields in the form.
class LoginForm with FormzMixin {
LoginForm({
this.username = const Username.pure(),
this.password = const Password.pure(),
});
final Username username;
final Password password;
@override
List<FormzInput> get inputs => [username, password];
}
void main() {
print(LoginForm().isValid); // false
}