【发布时间】:2022-08-22 22:43:10
【问题描述】:
I need like this -> click the image
如何在 Flutter 的下拉列表中获取国家列表,我只需要县列表和国家代码。
标签: flutter
I need like this -> click the image
如何在 Flutter 的下拉列表中获取国家列表,我只需要县列表和国家代码。
标签: flutter
这将为您提供带有国家代码的国家国旗下拉列表。 您可以找到国家代码列表here
class dropdown extends StatelessWidget {
const dropdown({
Key? key,
required this.locale,
}) : super(key: key);
final Locale? locale;
@override
Widget build(BuildContext context) {
_getFlag(String code) {
switch (code) {
case 'es':
return "??";
case 'de':
return "??";
case 'fr':
return "??";
case 'nl':
return "??";
case 'zh':
return "??";
default:
return "??";
}
}
return Padding(
padding: const EdgeInsets.all(8.0),
child: DropdownButtonHideUnderline(
child: DropdownButton(
icon: const Icon(
Icons.language,
color: kPrimaryColor,
),
items: I10n.all.map((locale) {
final flag = _getFlag(locale.languageCode);
return DropdownMenuItem(
child: Center(
child: Text(
flag,
style: const TextStyle(fontSize: 20),
)),
value: locale,
onTap: () {
final provider =
Provider.of<LocaleProvider>(context, listen: false);
provider.setLocale(locale);
},
);
}).toList(),
onChanged: (_) {},
)));
} }
【讨论】:
如果您还没有找到解决方案,请参考这个country_state_city 包。这可能是一个很大的帮助。
【讨论】: