Anyone know how to update a TextField dynamically?

Widgets & Design

I'm trying to update the initial value of a text field to match the tip amount from a container. I think it’s not possible with the text field, at least not the way I’m doing it, but I know there has to be a workaround. I’ve tested this with a normal text element, and it works. However, I want the tip amount to be customizable if necessary.

What have you tried so far?

I tried two approaches.
I have a 3-page state, selectedContainer, a manualTip boolean, and tipAmount. On initiation, I set an action to assign selectedContainer = 2.

First method:
In the text field's initial value, I use a single condition (if-then). If selectedContainer = 1, I call a custom function to calculate the tip. (This custom function works; I’ve tested it and tried it with regular text.) I repeat this logic for containers 2 and 3, using different tip percentages within the custom function. Additionally, I set an action on the containers that updates the page state to 1, 2, or 3, depending on the selected container. I also update manualTip = false. One more thing, i have an action for the TextField to update app state, if text changes, manualTip = True and selectedContainer = 0.

tipEg.mp4
3.59MB

Second method:
Instead of performing the calculations in the initial value of the text field, I handle them in the container's action. I update the page state’s tipAmount with the container’s calculated value. Then, I set the text field's initial value to tipAmount.

The issue:
The text field's initial value isn’t updating dynamically.

Did you check FlutterFlow's Documentation for this topic?
Yes
5
5 replies