Choose the right state type
Open State and create a named definition. Text stores a draft or selection, number stores a quantity or score, boolean stores a preference or condition, and list stores repeated entries. Use names describing their role rather than their screen position.
| Example | Type and purpose |
|---|---|
| draft | Text in a message field. |
| quantity | Number used in a cart total. |
| accepted | Boolean for consent or a condition. |
| messages | List rendered by a message-list widget. |
These values are local demonstration state until you add appropriate production storage or services. A variable is not automatically a database field or authenticated user record.
Bind an input and verify the result
- Create text state such as draft.
- Select the corresponding text field in Design.
- Choose that state in the Inspector binding selector.
- Switch to Preview and type a sample value.
- Use a supported display or action to verify the change.
Checkboxes and switches expect booleans; sliders expect numbers; dropdowns use text. Project checks identify incompatible or missing references. Update related widget/action references when renaming a state key.
Display values and numeric expressions
Supported text can reference state with braces. A cart can display quantity and compute a simple subtotal. Keep expressions within the supported model: this is not an arbitrary Dart execution field.
Quantity: {{quantity}}
Subtotal: ${{quantity*39}}If a text edit seems to disappear in Preview, inspect its binding. Change the relevant initial state or expression rather than unrelated static copy. The Dart tutorial explains underlying types and collections.
Connect state to an action
An input captures a value; an action decides what happens next. The chat kit appends draft to messages and then clears draft. A store can increase quantity and recalculate totals. A settings control can change a preference without a network service.
Running Preview state is separate from saved design definitions. Test initial values as well as values reached during interaction. Download a checkpoint before changing related bindings, then continue with multi-step workflows. Check the main flow again after applying an AI proposal so a presentation update does not silently replace a useful binding.
Example: inspect a cart quantity
In the commerce kit, inspect the quantity number state and the controls that increase or decrease it. Open Preview, add an item to the bag and change its quantity. Check both the displayed count and subtotal instead of relying only on a successful button animation.
Return to Design to inspect the related expression and action. Keep the value numeric. Replacing it with arbitrary text may break a calculation even when the label looks correct. Save a checkpoint before renaming the shared state or changing several related bindings at once.