How to show only specific countries on flutter using country_pickers package

Viewed 212

I am quite new in flutter I am building flutter dropdown country list using country_pickers: ^2.0.0, I am going to enclude only some countries, how can filter them.

2 Answers

CountryPicker has actually a field to make that:

child: ElevatedButton(
      onPressed: () {
        showCountryPicker(
          context: context,
          exclude: ['EN', 'PL','ES'],
          ....
          ....
          ),
        );
      },
      child: ...,
 ),

You can use exclude property by passing a list of unwanted countries.

For more info check explanation : country picker

It's very simple, you have to set countries isoCode list to the countryFilter.

Code

showCountryPicker(
    context: context,
    countryFilter: <String>['CD', 'CG', 'KE', 'UG'], // only specific countries
    onSelect: (){....},
)

Result

enter image description here

Related