Skip to content

FormController

Coordinates validation and submission for one mounted Form.

Learn more: Forms & validation

Import: package:fleury/fleury.dart, or package:fleury/fleury_core.dart in browser code.

// A State field; dispose it with the state.
final form = FormController();
// In build: rebuild on submission progress and submit from the button.
NotifierBuilder(
notifier: form,
builder: (context, form) => Form(
controller: form,
onSubmit: save, // async: the form stays busy until it completes
child: Column(
children: [
FormField(
validator: () => name.text.trim().isEmpty ? 'Enter a name.' : null,
child: TextInput(controller: name),
),
Button(
text: form.isBusy ? 'Saving…' : 'Save',
onPressed: form.isBusy ? null : form.submit,
),
],
),
),
)

A controller owns no field values. Application state remains the source of truth; the controller only drives the form that is currently attached to it. Create it once in State, pass it to Form, and dispose it alongside that state when external access is useful. Omit it for forms that submit through Form.of from inside their subtree.

This constructor has no public parameters.

FormController is defined in packages/fleury/lib/src/catalog/form.dart.

Category: Forms · All widgets