FormField
One validated value in a Form.
Learn more: Forms & validation
Import: package:fleury/fleury.dart, or package:fleury/fleury_core.dart in browser code.
FormField( validator: () => slug.text.isEmpty ? 'Enter a slug.' : null, child: TextInput(controller: slug, semanticLabel: 'Slug'),)// One validated value built from two controls.FormField.builder( validator: () => end > start ? null : 'End must be greater than start.', builder: (context, field) => Column( children: [ Stepper( label: 'Start', value: start, focusNode: field.focusNode, // where an error moves focus onChanged: (value) { setState(() => start = value); field.valueChanged(); }, ), Stepper( label: 'End', value: end, onChanged: (value) { setState(() => end = value); field.valueChanged(); }, ), ], ),)Details
Section titled “Details”The ordinary constructor discovers exactly one first-party value control
inside child, so no binding argument or specialized wrapper is needed.
Use FormField.builder for a custom or multi-control value.
Constructors
Section titled “Constructors”FormField()
Section titled “FormField()”Creates a field that automatically integrates one aware control in
child.
| Parameter | Type | Default | Description |
|---|---|---|---|
child: | Widget | required | Subtree containing the field’s one automatically integrated control. |
validator: | String? Function()? | — | Returns the current error by reading application-owned state. More |
error: | String? | — | Controlled external error, typically returned by a server. |
enabled: | bool | true | Whether the field takes part in validation. A disabled field is skipped when the form validates, shows no error, and is never focused as the first invalid field. |
showErrorMessage: | bool | true | Whether the field renders its current error below the control. |
errorBuilder: | Widget Function(BuildContext context, String error)? | — | Optional replacement for the default styled error text. |
validator: Keep validators free of side effects: revealed validation can refresh after forms, fields, or registered controls rebuild, including dependent fields.
FormField.builder()
Section titled “FormField.builder()”Creates a field whose custom control is built from its live state.
Use this for one logical value represented by a custom or multi-control
widget. The builder must call FormFieldState.valueChanged when its
app-owned value changes.
| Parameter | Type | Default | Description |
|---|---|---|---|
builder: | Widget Function(BuildContext context, FormFieldState field) | required | Custom-control builder used by FormField.builder. |
validator: | String? Function()? | — | Returns the current error by reading application-owned state. More |
error: | String? | — | Controlled external error, typically returned by a server. |
enabled: | bool | true | Whether the field takes part in validation. A disabled field is skipped when the form validates, shows no error, and is never focused as the first invalid field. |
focusNode: | FocusNode? | — | Optional external focus destination for FormField.builder. Otherwise attach FormFieldState.focusNode inside the builder. |
showErrorMessage: | bool | true | Whether the field renders its current error below the control. |
errorBuilder: | Widget Function(BuildContext context, String error)? | — | Optional replacement for the default styled error text. |
Source
Section titled “Source”FormField is defined in packages/fleury/lib/src/catalog/form.dart.
Category: Forms · All widgets