FFormBuilder
FFormBuilder is a widget that constructs and manages the form state, utilizing streams to refresh the UI dynamically as data changes. It provides a builder function that takes the form and returns a widget tree based on the form's state.
Example​
This is an example of how to use FFormBuilder to create a form with a single field. The builder function takes the form as a parameter and returns a widget tree based on the form's state.
void _submit() {
if(_form.check()) { // .isValid or .isInvalid start rebuild in FFormBuilder and returned boolean
print('Form Valid');
};
}
Widget build(BuildContext context) {
return FFormBuilder<LoginForm>(
form: _form,
builder: (context, form) {
EmailField email = form.email; // or FFormProvider.of<LoginForm>(context).get<NameField>()
return Column(
children: [
TextField(
key: email.key,
controller: _emailController,
decoration: InputDecoration(
labelText: 'Email',
errorText: email.exception.toString(),
),
),
ElevatedButton(
onPressed: _submit,
child: const Text('Submit'),
),
],
);
},
);
}
You can use ListenableBuilder to rebuild only the field that has changed, but you can use FFormProvider to rebuild all fields in the form.
void _submit() {
if(_form.check()) { // .isValid or .isInvalid start rebuild in FFormBuilder and returned boolean
print('Form Valid');
};
}
Widget build(BuildContext context) {
return ListenableBuilder<LoginForm>(
listenable: _form,
builder: (context, form) {
EmailField email = form.email; // or FFormProvider.of<LoginForm>(context).get<NameField>()
return Column(
children: [
TextField(
key: email.key,
controller: _emailController,
decoration: InputDecoration(
labelText: 'Email',
errorText: email.exception.toString(),
),
),
ElevatedButton(
onPressed: _submit,
child: const Text('Submit'),
),
],
);
},
);
}