|
| 1 | +--- |
| 2 | +title: Widget State |
| 3 | +--- |
| 4 | + |
| 5 | +# Widget State |
| 6 | + |
| 7 | +**Widget state** refers to the data or information that a widget holds, which can change over time and affect the widget's appearance or behavior. In FlutterFlow, the state is particularly important for form widgets, such as text fields, checkboxes, and radio buttons, as it allows these widgets to respond to user interactions. |
| 8 | + |
| 9 | +Additionally, **Widget Focus State** refers to the state that indicates whether a widget, such as a text field, currently has focus or not. When a widget has focus, it is ready to receive user input, and its appearance typically changes to indicate this (e.g., a text field with a blinking cursor). |
| 10 | + |
| 11 | +**Key Points:** |
| 12 | + |
| 13 | +- **Dynamic Data:** Represents values that change over time (e.g., user input in a text field). |
| 14 | +- **Automatic Management:** FlutterFlow handles the state, so developers do not need to write explicit state management code. |
| 15 | +- **Reactive Updates:** Changes in the state automatically update the widget's display. |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | +## Managing Widget States |
| 20 | + |
| 21 | +FlutterFlow simplifies state management by providing built-in support for handling widget states. This means developers do not need to manually create or manage the state of form widgets. Instead, FlutterFlow automatically manages the state for these widgets, ensuring a seamless and intuitive experience. |
| 22 | + |
| 23 | +Some examples of widget states exposed by FlutterFlow: |
| 24 | + |
| 25 | + - **Text Fields:** The state of text fields is automatically managed, including the input text and validation states. |
| 26 | + - **Checkboxes:** The state of checkboxes is managed, indicating whether they are checked or unchecked. |
| 27 | + - **Radio Buttons:** The state of radio buttons is managed to reflect the selected option. |
| 28 | + |
| 29 | + |
| 30 | +In the following example, we find widget state and widget focus state of a TextField being exposed by FlutterFlow on the page it was created and available as an option in the variable menu. |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | +:::note[Scope] |
| 35 | +Widget states are only available for access on the page or component where they were created. |
| 36 | +::: |
| 37 | + |
| 38 | +FlutterFlow allows you to update the state of these widgets through actions exposed by the platform. For example, if you want to clear a TextField when the Send button is clicked on a form-like page, then in the Actions Flow, you can find relevant actions such as **Clear TextField**. This enables dynamic interaction and state management directly within the visual development environment. |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | +## Action Triggers for Form Widgets |
| 44 | +FlutterFlow allows you to bind action triggers to widget states, such as calling an API on focus change of a textfield or changing the appearance of a button when a checkbox is checked. |
| 45 | + |
| 46 | +**Most common Action Triggers exposed by form widgets:** |
| 47 | + |
| 48 | +- **On Focus Change:** Triggered when a widget, such as a text field, gains or loses focus. |
| 49 | +E.g Showing additional tips or validation messages when the user starts typing in a text field. |
| 50 | + |
| 51 | +- **On Submit:** Triggered when a form or text field is submitted. E.g Validating input and submitting data when the user presses the enter key or clicks a submit button. |
| 52 | + |
| 53 | +- **On Change:** Triggered when the value of a widget changes. E.g Real-time validation or updating state as the user types in a text field or changes a selection in a dropdown. |
| 54 | + |
| 55 | +- **On Completed:** Triggered when a specific input is completed, such as entering a pincode. |
| 56 | +E.g Automatically moving to the next step in a process after a complete and valid pincode is entered. |
| 57 | + |
| 58 | +- **On Selected:** Triggered when an option is selected in widgets like choice chips, checkboxes, radio buttons, or sliders. E.g Updating the UI or performing actions based on the selected option. |
| 59 | + |
| 60 | +These triggers allow developers to create interactive and responsive applications by defining specific actions that occur in response to user interactions with form widgets. |
| 61 | + |
| 62 | + |
| 63 | + |
| 64 | + |
0 commit comments