I'm getting the following error from flutter dropdownbutton:
'items == null || items.isEmpty || value == null ||
items.where((DropdownMenuItem<T> item) {
return item.value == value;
}).length == 1'
My code looks the following:
MenuItems:
final _terminTypen = objectBox.getAllTerminTypen().map((item) {
return DropdownMenuItem<TerminTypDetails>(
value: item,
child: Text(item.name),
);
}).toList();
Selected Option:
TerminTypDetails _selectedTerminTyp = objectBox.getTerminTypById(1);
Object Class:
@Entity()
class TerminTypDetails {
@Id(assignable: true)
int id = 0;
String name;
TerminTypDetails({required this.name, required this.id});
factory TerminTypDetails.fromJson(Map<String, dynamic> json) {
return TerminTypDetails(id: int.parse(json['id']), name: json['name']);
}
Map<String, dynamic> toJson() {
return {"id": id, "name": name};
}
}
Dropdown:
DropdownButton<TerminTypDetails>(
hint: const Text("Termintyp"),
items: _terminTypen,
onChanged: (value) {
setState(() {
_selectedTerminTyp = value!;
});
},
value: _selectedTerminTyp,
)
What am I doing wrong?
I looked different ways here on stackoverflow to get rid of the error but they didn't work. In debug everything looks fine. List is filled, selected Option is filled and part of the list.