Issue
I'm quite new to flutter and I'm following a tutorial trying to implement a dropdown widget (code is shown below) in my app. But every time I launch the page, I get this result Exception has occurred. _TypeError (type 'List<DropdownMenuItem>' is not a subtype of type 'List<DropdownMenuItem>?')
Here is a screenshot of my problem
Here is my code
Widget selectDropdown(
BuildContext context,
Object initialValue,
dynamic data,
Function onChanged, {
Function onValidate,
}
) {
return Align(
alignment: Alignment.topLeft,
child: Container(
height: 75,
width: 100,
padding: const EdgeInsets.only(top: 5),
child: DropdownButtonFormField(
hint: const Text(
"Select",
style: TextStyle(
color: Colors.white
)
),
isDense: true,
value: null,
decoration: fieldDecoration(context, "", ""),
onChanged: (VariableProduct newValue) {
FocusScope.of(context).requestFocus(FocusNode());
onChanged(newValue);
},
validator: (value) {
return onValidate(value);
},
items: data != null ?
data.map<DropdownMenuItem<VariableProduct>>(
(VariableProduct data) {
return DropdownMenuItem<VariableProduct>(
value: data,
child: Text(
data.attributes.first.option + " " + data.attributes.first.name,
style: const TextStyle(color: Palette.backgroundColor)
),
);
}
).toList()
: null,
)
),
);
}
I will be glad if I can be helped. Thank you
Solution
Add type parameter to DropdownButtonFormField:
DropdownButtonFormField<VariableProduct>
Answered By - 聂超群
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.