srtraj / dropdown_textfield

custom dropdown
MIT License
8 stars 48 forks source link

Fails to Update Initial Value within setState #39

Closed AravinthC-18 closed 3 months ago

AravinthC-18 commented 11 months ago

I'm encountering an issue in my Flutter app where the initial value of a Dropdown TextField fails to update when I call setState. To reproduce the problem, I've created a Flutter project, set an initial value for the Dropdown, and then attempted to change the value within a setState function. However, despite expecting the Dropdown to reflect the new value after setState, it consistently retains its initial value. This issue persists even though I've ensured the state variable changes correctly within setState. ` DropDownValueModel list = DropDownValueModel( name: index[i].name, value: index[i].id);

setState((){ name=index[0]; }); //BUT GET VALUE FROM 'name' VARIABLE DropDownTextField( dropDownList: list, initialValue: name, //NOT UPDATED ), ` I would greatly appreciate guidance or solutions to address this unexpected behavior. Thank you!

Prathap-Aosta commented 11 months ago

I have the same issue

srtraj commented 3 months ago

@AravinthC-18 The initial value will be updated only on the first render. After that, if you want to add a value, use the controller. controller.setDropDown(value)