将印度设置为默认国家/地区标志 country_picker 颤抖?
set india as default country flag country_picker flutter?
我正在处理一个 flutter 项目,有一个下拉菜单默认显示所有国家/地区。它显示阿富汗,但我想默认显示印度:
CountryPickerDropdown(
onTap: () =>
FocusScope.of(context)
.requestFocus(
FocusNode()),
onValuePicked: (
Country country) {
print("${country.name}");
},
itemBuilder: (Country country) {
return Row(
children: <Widget>[
CountryPickerUtils
.getDefaultFlagImage(
country),
Expanded(
child: Text(
country.isoCode,
),
),
],
);
},
itemHeight: null,
isExpanded: true,
icon: SizedBox(),
)
有人知道怎么做吗?提前致谢
试试下面的代码希望对你有帮助。只需设置 initialValue
使用 country_pickers
包 here
您的小部件:
CountryPickerDropdown(
initialValue: 'in',
itemBuilder: _buildDropdownItem,
onValuePicked: (Country country) {
print("${country.name}");
},
),
你的方法:
Widget _buildDropdownItem(Country country) => Container(
child: Row(
children: <Widget>[
CountryPickerUtils.getDefaultFlagImage(country),
SizedBox(
width: 8.0,
),
Text("+${country.phoneCode}(${country.isoCode})"),
],
),
);
您的结果屏幕->
我正在处理一个 flutter 项目,有一个下拉菜单默认显示所有国家/地区。它显示阿富汗,但我想默认显示印度:
CountryPickerDropdown(
onTap: () =>
FocusScope.of(context)
.requestFocus(
FocusNode()),
onValuePicked: (
Country country) {
print("${country.name}");
},
itemBuilder: (Country country) {
return Row(
children: <Widget>[
CountryPickerUtils
.getDefaultFlagImage(
country),
Expanded(
child: Text(
country.isoCode,
),
),
],
);
},
itemHeight: null,
isExpanded: true,
icon: SizedBox(),
)
有人知道怎么做吗?提前致谢
试试下面的代码希望对你有帮助。只需设置 initialValue
使用 country_pickers
包 here
您的小部件:
CountryPickerDropdown(
initialValue: 'in',
itemBuilder: _buildDropdownItem,
onValuePicked: (Country country) {
print("${country.name}");
},
),
你的方法:
Widget _buildDropdownItem(Country country) => Container(
child: Row(
children: <Widget>[
CountryPickerUtils.getDefaultFlagImage(country),
SizedBox(
width: 8.0,
),
Text("+${country.phoneCode}(${country.isoCode})"),
],
),
);
您的结果屏幕->