How do I search in Flutter DropDown button

Nick picture Nick · Nov 19, 2018 · Viewed 9.7k times · Source

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"
            },

Answer

mike picture mike · Feb 2, 2020

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;
  }