I am using declare an array –
final List<DropdownMenuItem<String>> listDropDown;
And I use the following construction –
class DropDown extends StatelessWidget {
final String dropDownValue;
final List<DropdownMenuItem<String>> listDropDown;
DropDown(this.dropDownValue, this.listDropDown);
But I get an error –
The argument type 'List<dynamic>' can't be assigned to the parameter type 'List<DropdownMenuItem<String>>?'.
In this place –
return DropdownMenuItem(
value: dropDownValue,
child: Text(items, style: TextStyle(fontFamily: "Mark-Pro", fontSize: 18, fontWeight: FontWeight.w500, color: configColors.darkBlue),),
);
}).toList(),
full dropDownButtom –
child: DropdownButton(
items: listDropDown.map((String items) {
return DropdownMenuItem(
value: dropDownValue,
child: Text(items, style: TextStyle(fontFamily: "Mark-Pro", fontSize: 18, fontWeight: FontWeight.w500, color: configColors.darkBlue),),
);
}).toList(),
// Initial Value
value: dropDownValue,
// Down Arrow Icon
icon: const Icon(Icons.keyboard_arrow_down),
// Array list of items
// After selecting the desired option,it will
// change button value to selected value
onChanged: (String? newValue) {
mystate(() {
dropDownValue = newValue!;
});
},
),
>Solution :
The issue is in calling DropDown, you are passing List instead of List<DropdownMenuItem> to DropDown’s listDropDown.
try this:
DropdownButton<String>(
items: listDropDown.map((String items) {
return DropdownMenuItem<String>(
value: dropDownValue,
child: Text(items, style: TextStyle(fontFamily: "Mark-Pro", fontSize: 18, fontWeight: FontWeight.w500, color: configColors.darkBlue),),
);
}).toList(),
// Initial Value
value: dropDownValue,
icon: const Icon(Icons.keyboard_arrow_down),
onChanged: (String? newValue) {
mystate(() {
dropDownValue = newValue!;
});
},
)