flutter - 在颤振中,有没有办法以编程方式在 CountryPickerDropdown 中设置初始值?
问题描述
我正在尝试以编程方式在 countrypickerdropdown 中设置 initialValue,但无法这样做,而是设置了 initValue ('us') 而不是我的编程值。片段如下
child: CountryPickerDropdown(
initialValue: countryCode?? 'us',
itemBuilder: _buildDropdownItem,
onValuePicked: (Country country) {
setState(() {
countryName = country.name;
print("${country.name}");
intlPhoneCode = country.phoneCode;
print("${intlPhoneCode}");
countryCode = country.isoCode;
phoneIsVerified = false;
});
}
countryCode 值是从 api 调用中获取的,如下所示:
Future<void> getProfile(String id) async {
try{
profile = await apiService.getProfile(id);
countryCode = profile['countryCode'];
}catch(ex){
...
}
}
我什至不能在 initState 中做到这一点。
解决方案
推荐阅读
- javascript - JS - 将整数保存为浮点数
- javascript - 具有依赖关系的 Webpack 多文件
- python - 在 CSV 文件中搜索特定字符串时遇到问题
- reactjs - React 测试库 fireEvent.change 不能与 fireEvent.submit 一起使用
- sql-server - 在 SQL Server 2008 R2 中使用 FORMAT 的替代方法
- hashicorp-vault - 调整密钥时 Vault HashiCorp 参数过多错误
- php - PHP 脚本在没有重定向的情况下运行
- reactjs - 对大量项目的反应状态
- scala - 在 Flink (Scala) 的内存缓存中?无法加载番石榴
- menu - Prestashop 在特定页面上添加侧边菜单