data comes from Firebase. its initial value is companyCountryString. I pass selected newValue to companyCountryString with onChanged's setState function.
DropdownButton(
value: companyCountryString,
icon: const Icon(Icons.keyboard_arrow_down_outlined),
items:
countriesList.map((String countries) {
return DropdownMenuItem(
value: countries,
child: Text(countries),
);
}).toList(),
onChanged: (String? newValue) {
setState(() {
companyCountryString = newValue!;
});
})
There is also a streambuilder above of the dropdownbutton to feed it as follows. It get and pass the values of Firebase to this Dropdownbutton.
body: StreamBuilder(
stream: db.collection("Companies").doc(widget.editedID).snapshots(),
builder: (context, AsyncSnapshot<DocumentSnapshot> snapshot) {
if (snapshot.hasData == false) {
return Center(
child: CircularProgressIndicator(),
);
}
Companies company = Companies.docToObject(snapshot.data!);
TextEditingController companyName =
TextEditingController(text: company.companyName);
TextEditingController companyShortName =
TextEditingController(text: company.companyShortName);
TextEditingController companyAddress =
TextEditingController(text: company.companyAddress);
String companyCountryString = company.companyCountry.toString();
TextEditingController companyPhone =
TextEditingController(text: company.companyPhone);
TextEditingController authUser_1 =
TextEditingController(text: company.authUser_1);
TextEditingController authUser_2 =
TextEditingController(text: company.authUser_2);
TextEditingController authUser_3 =
TextEditingController(text: company.authUser_3);
TextEditingController authUser_4 =
TextEditingController(text: company.authUser_4);
User select to change existing dropdown value. Setstate, sets the new value but Setstate also runs builder. And all process go to initial values. I have to use set state to update dropdown. But It also create a deadlock handicap. Could you please give a clue ?
I am not sure about does StreamBuilder cause trouble like FutureBuilder with setState, you can try with separating context.
How to separate it ? I dont understand.
creating another widget
Обсуждают сегодня