FormValidator class

Form Validation Helper.

Bridges Magic validation rules with Flutter's native Form widgets. Use FormValidator.rules() to create validators for WFormInput, TextFormField, or any FormField widget.

final _formKey = GlobalKey<FormState>();
final _email = TextEditingController();

Form(
  key: _formKey,
  child: Column(
    children: [
      WFormInput(
        controller: _email,
        type: InputType.email,
        label: 'Email',
        className: 'p-3 border rounded-lg error:border-red-500',
        validator: FormValidator.rules(
          [Required(), Email()],
          field: 'email',
        ),
      ),
      FilledButton(
        onPressed: () {
          if (_formKey.currentState!.validate()) {
            // Form valid! Send clean data to controller
            controller.attemptLogin(email: _email.text.trim());
          }
        },
        child: Text('Submit'),
      ),
    ],
  ),
)

With Password Confirmation

final _password = TextEditingController();
final _passwordConfirm = TextEditingController();

WFormInput(
  controller: _passwordConfirm,
  type: InputType.password,
  label: 'Confirm Password',
  validator: FormValidator.rules(
    [Required(), Same('password')],
    field: 'password confirmation',
    extraData: {'password': _password.text},
  ),
)

Constructors

FormValidator()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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

Static Methods

rules<T>(List<Rule> rules, {String field = 'field', Map<String, dynamic>? extraData, MagicController? controller, Map<String, String>? messages}) String? Function(T?)
Create a FormFieldValidator from Magic rules.