Home > database >  The return type 'String?' isn't a 'bool', as required by the closure's
The return type 'String?' isn't a 'bool', as required by the closure's

Time:05-30

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();
  • Related