DEV Community

Cover image for Put Repeated Form Rules on the Model
YeLinAung for dust

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

Put Repeated Form Rules on the Model

Flutter TextFormField validator code beside Dust model validation annotations

Flutter forms usually start with a TextFormField.validator.

That works well for one screen.

The problem starts when the same rule appears in more places. Signup page. Profile page. Admin form. Test setup.

Now the email rule is copied into widgets.

Dust Validation lets the model own that rule.

Add Validate() to the model. Put @Validate(...) on the field. Dust generates validate() for the full object.

In Flutter packages, Dust can also generate field validator helpers for TextFormField.

So the widget can stay small. The model keeps the rule. Tests can validate the same object before the UI is involved.

Read the Dust validation rules guide.

Dust #Validation #Flutter #Dart #CodeGeneration

Top comments (0)