DEV Community

Cover image for Keep Form Validation Rules Close to the Model
YeLinAung for dust

Posted on Originally published at dust-codegen.pages.dev

Keep Form Validation Rules Close to the Model

Flutter TextFormField validator beside a Dust validation model

Flutter forms usually start with TextFormField.validator. That works well for one field on one screen.

The problem starts when the same rule appears in more than one place. Signup. Profile edit. Checkout. Tests.

Dust lets the model own the rule. Add Validate() to the model, put the field rule beside the field, and run dust build.

Then the form can call the generated validator helper. The model can still validate itself before submit.

Read the Dust validation guide.

Dust #Validation #Flutter #Dart

Top comments (0)