DropdownButton with dynamic items list

Hi all,

I need a dropdown (of email addresses) that provides 3 features: 1) select a value from the dropdown, 2) filter the list of values (emails) based on a pattern, then section of a value from the filtered list, and 3) the ability to add a new value when it's not in the lis (1 or 2). The list of values is from a Firestore collection, but that is not relevant to the problem. The Flutterflow Dropdown widget with Search enabled pretty much provides functionality 1 and 2, but it lacks 3 (or I couldn't get it to work).

Instead of using the out-of-the-box widget, I wrote an EmailDropdown custom widget based on the Flutter DropdownButton widget. I have a version that tries to implement functions 1 and 2, but I couldn't get it to work yet. The standard funcition 1) is no problem but I'm struggling with 2). When I set the filter, I can filter the list of values (emails) using list.where((email) => email.toLowerCase().contains(_filter.toLowerCase()).map(..) then build the List<DropdownMenuItem<String>>. The filter string is assigned in onChanged: in the setState() method. I can print the filtered list of emails and can verify that the filter works fine. But the dropdown list is not updated, until I change the focus. Only when I go back and select the dropdown list I see that the list was updated. What I need, however, is a continuous update of that dropdown items based on the filter changes. That's what the FF Dropdown does perfectly, so there must be a way to get this working. And again, I need feature 3, that's why using the FF Dropdown is no option here.

Any suggestions on how to get this working is appreciated - thanks.

Andreas

EmailDropdownButton.pdf
22.43KB

1