I wanted to add this country code to DropdownButton
Country is my data class.
DropdownButton<Country> androdDropDown(BuildContext context) {
List<DropdownMenuItem<Country>> dropDownItems = [];
List countryList =
getAppState(context).counties.where((i) => i.code).toList();
return DropdownButton<Country>(
value: countryList.reversed.first,
items: dropDownItems,
onChanged: (value) {},
);
}
the error occurred in i.code
CodePudding user response:
In the line:
List countryList =
getAppState(context).counties.where((i) => i.code).toList();
You are trying to filter the countries where the code is equal to true. But the variable code is not a boolean but a String?. Try replacing it with:
List countryList =
getAppState(context).counties.where((i) => i.code != null).toList();