flutter - Flutter:如何在 Country Pickers DropDown 库中设置值
问题描述
我在设置 country_code_picker 和 country_state_city_picker 库的值时遇到问题。我尝试在编辑选项中设置值,这是我之前在创建新广告时选择的,但它不起作用。也许有人有与他们合作的经验,或者对我需要做什么有一些建议。
Firestore 中的数据。由于某种原因,Contry 代码值为空
这个问题在应用程序中的外观如何,您如何查看这些选择器中的数据未设置
新广告创建时的代码
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;
});
})
编辑时的代码并尝试设置保存的数据
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;
});
},)
解决方案
推荐阅读
- excel - 循环遍历包含特定文本的行直到空白
- azure - Azure Powershell 从 CSV 文件中标记 VM
- bash - 如何在多线程while循环之外扩展变量
- php - Laravel 组合两个表并从其中一个表中计算值
- laravel - 如何验证表单中动态添加的输入?
- javascript - 使用 setState 方法添加子对象
- json - 如何快速将 OTP 发送到注册的手机号码?
- ios - 如何从表格视图单元格中的图像手势获取 indexPath
- fortran - 如何使用 gfortran 编译联合/映射
- ios - 没有 Cocoapods - 需要手动为 iOS 添加性能监控