I have problem with setting value of country_code_picker and country_state_city_picker libraries. I try to set value in edit options, that i have choosed before when created new ad, but it doesn't work. Maybe someone has experience working with them, or have some suggestion what i need to do.
Data in Firestore. Contry code value is empty for some reason
How this problem looks in the app, how you can see data in these pickers doesn't set
Code when New ad creates
String countryvalue = '';
String countrycode = '';
String cityvalue = '';
String statevalue = '';
// Adding new ad
Future newAdd() async{
return ads.add({
'title' : titlecontroller.text,
'location': '$countryvalue,$cityvalue',
'currency' : currentcurreny,
'country' : countryvalue,
'countrycode' : countrycode,
'city' : cityvalue,
'state' : statevalue,
'phone' : phonecontroller.text,
'price' : pricecontroller.text,
'desc' : desccontroller.text,
'url1' : widget.url,
'url2' : widget.url2,
'url3' : widget.url3,
'category' : categoryCurrentItem,
'userid' : user != null? user!.uid : googleUser!.id,
'time' : Timestamp.now()
});
}
// Using country_code_picker library
CountryCodePicker(
initialSelection: 'EN',
onChanged: (CountryCode country){
setState(() {
countrycode = country.dialCode!;
});
},
)
// Using country_state_city_picker library
SelectState(
onCountryChanged: (String value) {
setState(() {
countryvalue = value;
});
},
onCityChanged: (String value) {
cityvalue = value;
},
onStateChanged: (String value) {
setState(() {
statevalue = value;
});
})
Code when Edit and try to set saved data
String? country;
String? city;
String? state;
String? countrycode;
// Using country_code_picker library
CountryCodePicker(
initialSelection: widget.countrycode,
onChanged: (CountryCode country){
setState(() {
widget.countrycode = country.dialCode!;
});
},
)
// Using country_state_city_picker library
SelectState(
onCountryChanged: (String value) {
setState(() {
widget.country = value;
});
},
onCityChanged: (String value) {
setState(() {
widget.city = value;
});
},
onStateChanged: (String value) {
setState(() {
widget.state = value;
});
},)