loform
loform is still experimental, missing features and bugs are to be expected.
loform is a low-code and lightweight flutter form library, inspired by formik — the world’s most popular form library for react, used in production at airbnb, stripe, nasa and more.
features
- no boilerplate: 90% less code compared to bloc + formz.
- informational: provides a lot of useful states (
touched
,status
,error
) for each field in the form. - server-errors friendly: unlike flutter_form_builder which requires external errors to be managed by a separate state.
- reusable and easy validation: uses the builder pattern for building validations.
simple usage
this is a simple example, for a more complex one see the registerform
widget.
class simpleform extends statelesswidget {
@override
widget build(buildcontext context) {
// [1] wrap your form with [loform] widget.
return loform(
// [2] choose when the submit button is enabled using form status.
submittablewhen: (status) => status.isvalid || status.issubmitted,
// [3] implement what happens when the form is submitted.
onsubmit: (values) async {
print('hi, ${values.get('name')}!');
return true; // successful submission
},
builder: (form) {
return column(
children: [
// [4] use [lotextfield] instead of the normal [textfield].
lotextfield(
// [5] this name will be used to get the field's value.
name: 'name',
// [6] provide a validation scheme using [lovalidation].
validate: lovalidation().required().build(),
),
const sizedbox(height: 32),
elevatedbutton(
// [7] call the [submit] method.
onpressed: form.submit,
child: const text('submit'),
),
],
);
},
);
}
}
Comments are closed.