I am trying to make a form and have a dropdown menu in it but it seems to not be working. For reference:
myGroups - passed into the widget as an object of Groups
groupSelected - an object Groups
DropdownButtonFormField<Groups>(
items: myGroups
.map((label) => DropdownMenuItem(
child: Text(label.groupName),
value: label,
))
.toList(),
hint: Text('Group'),
value: groupSelected,
onChanged: (value) {
setState(() {
groupSelected = value;
});
},
),
I keep getting an error saying
The following assertion was thrown building Builder(dirty, dependencies: [_FocusMarker]):
There should be exactly one item with [DropdownButton]'s value: Instance of 'Groups'.
Either zero or 2 or more [DropdownMenuItem]s were detected with the same value
'package:flutter/src/material/dropdown.dart':
Failed assertion: line 855 pos 15: 'items == null || items.isEmpty || value == null ||
items.where((DropdownMenuItem<T> item) {
return item.value == value;
}).length == 1'