admin管理员组文章数量:1122846
I want to display CountryFlags, defined in package:country_flags/country_flags.dart, in a flutter DropdownMenu. However, this sample code below only displays a ? :
dropdownMenuEntries: list.map<DropdownMenuEntry<String>>((String value) {
return DropdownMenuEntry<String>(
value: value,
label: value,
labelWidget: CountryFlag.fromLanguageCode(
'in',
width: 20,
height: 20,
));
}).toList(),
The same code modified to display an image, however, works fine:
dropdownMenuEntries: list.map<DropdownMenuEntry<String>>((String value) {
return DropdownMenuEntry<String>(
value: value,
label: value,
labelWidget: Imagework('/250?image=9'));
}).toList(),
Is anyone able to assist?
I want to display CountryFlags, defined in package:country_flags/country_flags.dart, in a flutter DropdownMenu. However, this sample code below only displays a ? :
dropdownMenuEntries: list.map<DropdownMenuEntry<String>>((String value) {
return DropdownMenuEntry<String>(
value: value,
label: value,
labelWidget: CountryFlag.fromLanguageCode(
'in',
width: 20,
height: 20,
));
}).toList(),
The same code modified to display an image, however, works fine:
dropdownMenuEntries: list.map<DropdownMenuEntry<String>>((String value) {
return DropdownMenuEntry<String>(
value: value,
label: value,
labelWidget: Image.network('https://picsum.photos/250?image=9'));
}).toList(),
Is anyone able to assist?
Share Improve this question edited Nov 21, 2024 at 10:50 DarkBee 15.8k8 gold badges69 silver badges110 bronze badges asked Nov 21, 2024 at 10:45 user1052610user1052610 4,66914 gold badges60 silver badges108 bronze badges 4 |2 Answers
Reset to default 1The ? symbol indicates that the flag for the provided language code (in
) does not exist. This happens because in
is not a valid language code. If you're looking for the language code for India, it is hi
.
As stated in the package documentation:
For a list of supported languages, visit Lingoes Language Codes. (Please note that not all language codes on the list are supported.)
Make sure the language code you use is supported by the country_flags package. If it still doesn't work, double-check the package documentation for limitations or updates regarding supported language codes.
You can solve it changing this line inside file flag_code:
.singleWhereOrNull((entry) => entry.key== languageCode)
to
.singleWhereOrNull((entry) => entry.value == languageCode)
You can find it inside the flag_code.dart and in
static String? fromCountryCode(String countryCode)
The mistake here looks like that are in the name of country. The package is using entry.key but those values are like "hi" to "in" or "pt-br" to "br"... So if you really want to use "in" or "br" do the change in code.
Or you can simply pass the right "key" to the package so, wont be necessary change anythinhg.
本文标签: flutterDisplaying a CountryFlag in a dropdown listStack Overflow
版权声明:本文标题:flutter - Displaying a CountryFlag in a dropdown list - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736311680a1934827.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
CountryFlag.fromLanguageCode(...)
actually returns? – DarkBee Commented Nov 21, 2024 at 10:50SizedBox
to a property which expect anImage
, e.g.labelWidget: Image.network('https://picsum.photos/250?image=9'))
– DarkBee Commented Nov 21, 2024 at 11:05