Hi I'm new to Flutter.
I had been getting an exception There should be exactly one item with [DropdownButton]'s value: .
when using DropdownButton
class. And it was resolved once by setting an initial select referring to this
CodePudding user response:
There should be exactly one item with [DropdownButton]'s value: means you are having same value more than one DropdownMenuItem. You can convert the data-list to Set, most time it works.
Here the items is
List<String> items = [...];
String? selectedItem;
And the dropDownButton
DropdownButton<String?>(
items: items
.toSet()
.map(
(e) => DropdownMenuItem<String?>(
value: e,
child: Text(e),
),
)
.toList(),
onChanged: (value) {},
)