Quick Start
Build a complete Course Enrollment form in 5 minutes using the FormBuilder DSL.
The Scenario
We will create an LMS enrollment form that:
- Collects student name, email, and phone number
- Lets the student select a course and enrollment type
- Shows payment fields only when "Paid Enrollment" is selected
- Validates all inputs with appropriate rules
- Groups preferences into a collapsible section
Import the DSL
The DSL import gives you FormBuilder, all field builders, and the When class for conditional rules.
Build the Form
Chain field builders fluently — starting a new field auto-finalizes the previous one, so no .done() calls are needed.
enrollment_form.dartUse the Form
The build() method returns a Form object with a fully wired FormGroup. You can render it or work with it programmatically.
Render in Flutter
Use the form's content builder system to render it. The default vertical layout renders fields in order; explicit side-by-side layout uses row blocks.
enrollment_page.dart
What You Built
In under 50 lines of DSL code, you created a form with:
- 6 fields across 3 types (text, select, date)
- Validation -- required, email, min length
- Conditional visibility -- payment method appears only for paid enrollment
- Sequential layout -- fields render in the order declared by the DSL
- Collapsible section -- preferences grouped and collapsible
- Reactive state -- FormGroup-backed values with MobX observability
Key Patterns
| Pattern | How |
|---|---|
| Auto-finalize | Starting a new field commits the previous one -- no .done() needed |
| Fluent validation | .required().email().minLength(2) chains naturally |
| Conditional rules | .showWhen(When.fieldEquals(...)) for declarative visibility |
| Rows | Use FormRowBlock in the runtime model or Row blocks in the visual editor for side-by-side fields |
| Sections | .section('Title', (s) => s.field(...)) for visual grouping |
Next Steps
- Philosophy -- Understand the 6 design principles
- Form Model -- Deep dive into Form, FormRowBlock, FormSection, and StepForm
- Field Types -- All 12 field types with configuration options
- Validation Patterns -- Real-world validation examples