This is the error I have got:
Here is my DropdownButton code:
DropdownButton countryPicker() {
return DropdownButton<String>(
onChanged: (value) {
setState(() {
country = value;
});
},
value: country,
hint: Text(country),
items: countries(),
);
}
List<DropdownMenuItem<String>> countries() {
List<DropdownMenuItem<String>> list = [];
countryDetails.forEach((c) {
list.add(DropdownMenuItem<String>(
child: Text(c.countryName),
value: c.countryName,
));
});
return list;
}
All of my data list is in countryDetails variable.
And the list is like this:
[
{
"country_name": "Andorra",
"alpha2_code": "AD",
"states": [
{"state_name": "Andorra la Vella"},
{"state_name": "Canillo"},
]
},
..............
..............
]
So, whats the problem here?
In the error it says you have two or more DropdownMenuItem
with the same value
, which is not allowed.
When I take a look at your code, it seems like you are passing c.countryName
as the value, but could you double check and make sure that all of your country_name
are unique?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.