Closed MuKhAlm closed 1 month ago
I am having the similar problem. Were you able to find a solution ?
I found a workaround, here it goes:
Assuming you use the same template shown above (and in their examples), you will have two lists. items for all items to display and select and unselect from. selectedItems, for well, selected items.
At the start of the Widget build method (SubjectField build method in my example) you have to initialize isSelected with the items from the items list which you want to initialize with.
In my case it became the following:
for (final subject in items) {
for (final s in widget.initialValue!) {
if (subject.id == s.id) {
if (!selectedItems.contains(subject)) {
selectedItems.add(subject);
}
}
}
}
The solution might not be the best. But it works. I'd advice you to give FormBuilder package a try. They also have their own version of a multi-value drop-down field.
If you are still have trouble, please do tell. It'd be my pleasure to help ^_^
I am having trouble setting a default/initial value for [DropdownButtonFormField2].
I somehow got the [DropdownMenuItem]s to have initial values. However, I could not get the field that shows the items selected to have an initial value.
Is there a way for me to assign initial values for the Widget or is there no such feature?
Here is my code if that helps: