WellFormed constructor
WellFormed(})
A Form that is suitable for the most common scenarios.
fields
the Form's fields.
submit
a factory function for building the submission widget.
reset
an optional factory function for building the reset widget.
leading
an optional extra widget that will be placed on the leftmost
position alongside the submit
and reset
widgets.
formKey
the form state key; if omitted, a new one will be generated.
Implementation
WellFormed(
List<Widget> fields, {
required ToSubmit submit,
ToReset? reset,
Widget? leading,
GlobalKey<FormState>? formKey,
Key? key,
}) : _toForm = ((context) {
final fkey = formKey ?? GlobalKey<FormState>();
return SafeArea(
child: Column(
children: [
Form(
key: fkey,
child: Column(children: fields),
),
ListTile(
leading: leading ?? const SizedBox(),
title: submit(() {
final formState = fkey.currentState;
if (formState != null) {
if (formState.validate()) {
formState.save();
}
}
}),
trailing: reset == null
? const SizedBox()
: reset(() {
final formState = fkey.currentState;
if (formState != null) {
formState.reset();
}
}),
),
],
),
);
}),
super(key: key);