Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I search in Flutter DropDown button

I have a list of the countries name in local json. I can load my local json and assign to DropDown button. there is a 193 countries in json file as ex. shown below. If I want to select United State, user have to scroll all the way down. How can enter a countries name such as; if I user enter U or u the dropdown can makes quick filtering and list all the countries that starts with U such as United State. How do I search in Flutter DropDownbutton items?

{
    "country": [
        {
            "countryCode": "AD",
            "countryName": "Andorra",
            "currencyCode": "EUR",
            "isoNumeric": "020"
        },
        {
            "countryCode": "AE",
            "countryName": "United Arab Emirates",
            "currencyCode": "AED",
            "isoNumeric": "784"
        },
        {
            "countryCode": "AF",
            "countryName": "Afghanistan",
            "currencyCode": "AFN",
            "isoNumeric": "004"
        },
        //...
    ]
}
like image 401
Nick Avatar asked Nov 19 '18 09:11

Nick


People also ask

How do you search data from API list in flutter searchable dropdown list?

If you're using a List<Object> from an API response, you can map the keywords that you need to filter from to a List<String> to be used in the Autocomplete widget. The index can be used as a reference on the List<Object> to fetch the Object.

How do you get dropdown index in flutter?

Steps to create dropdown: Step 1: Add a variable called dropdownValue that holds the currently selected item. Step 2: Add the DropdownButton widget to your page. Step 3: Inside the DropdownButton, add the value parameter and assign the dropdownValue that we created in step 1.


1 Answers

You can use searchable_dropdown package instead: https://pub.dev/packages/searchable_dropdown

And here is my example code searchable_dropdown dont work with class list

Make sure that you put the following if you use a class list like my example

  @override
  String toString() {
    return this.key;
  }
like image 80
mike Avatar answered Sep 19 '22 19:09

mike