Reputation: 37
Widget _buildDropDownButton(String currencyCategory) {
return DropdownButton(
value: currencyCategory,
items: currencies
.map((String value) => DropdownMenuItem(
value: value,
child: Row(
children: <Widget>[
Text(value),
],
),
))
.toList(),
onChanged: (String value) {
if(currencyCategory == fromCurrency){
_onFromChanged(value);
}else {
_onToChanged(value);
}
},
);
}
Hi, I have an issue in this part of sample code, in this part of code:
onChanged: (String value) {
if(currencyCategory == fromCurrency){
_onFromChanged(value);
}else {
_onToChanged(value);
}
},
It shows an error The argument type 'void Function(String)' can't be assigned to the parameter type 'void Function(String?)?'
I tried placing final void Function() onChanged;
or final VoidCallback onChanged;
but it expects and identifier. Is there something that I missed?
Upvotes: 1
Views: 1143
Reputation: 131
This is because of the null safety, the value for the dropdown can be null when nothing is selected. Add a "?" after the String type declaration to be like onChanged(String? value) {//on change logic}
.
Checkout the flutter DropdownButton example.
Upvotes: 2