keyed_form

Validation

Declare field rules in the schema and add cross-field rules with refine.

Comparison copy: this is the previous documentation and may contain outdated guidance. Read the reorganized guides

Synchronous rules live alongside the field's schema. The generated validator reports errors against typed field keys.

dart
final _loginSchema = ks.object({
  'email': ks.string(error: .text('Email is required')).email(),
  'password': ks.string().min(8),
});

Compose rules#

Rules such as .required(), .email(), .min(...), and .max(...) can be chained on a field schema. Provide .text(...) messages where the default is not right for your app.

Use .refine(...) when validity depends on more than one field, such as matching password and confirmation values. Keep the predicate synchronous and attach the result to the field that should display the error.

Choose when errors appear#

KeyedFormMode controls visibility while users edit. Submit through the controller to validate the full draft and reveal invalid fields. For asynchronous checks, see async validation.