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?
2
Answers
You can solve it changing this line:
to
You can find it inside the flag_code.dart and in
The mistake here looks like that are in the package. They are using entry.key but those value are like "hi" to "in" or "pt-br" to "br"…
Or you can simply pass the right "key" to the package so, wont be necessary change anythinhg.
The ? symbol indicates that the flag for the provided language code (
in
) does not exist. This happens becausein
is not a valid language code. If you’re looking for the language code for India, it ishi
.As stated in the package documentation:
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.