I want to implement a text search in Dropdown Flutter/Dart.
I want to use Flutter/Dart DropdownMenu class.
I don’t want to use DropDownButton b/c it does not have a search.
The DropdownMenu Search class has SearchCallBack.
The DropdownMenu class has 3 key things: List, Controller, and SearchCallBack.
I want to use Controller to search the Controller’s input text.
The SearchCallBack has two things: list and query.
I am not certain how to define the SearchCallBack correctly.
Could you please provide example of SearchCallBack.
Thank You
2
Answers
Imagine a function that takes a list of
DropdownMenuEntry
s ("entries") and aString
("query"), and returns anint
for the index of aDropdownMenuEntry
in the list that matches the string. This is the function you are passing as theSearchCallback
parameter. If you leave it blank, it will default to a function that returns the index of first entry that contains the query anywhere in it. You can write your own function to customize the search. For example, here is a function you could write that returns the index of the first entry that matches the query exactly.I used flutter auto complete widget like below and also I implementing this using TextEditingController also in generic clean way let me know if you have any questions