-3

I am working with a flutter project and there is a dropdown menu that shows all the countries as a default. It shows Afghanistan, but I want to show India as default:

CountryPickerDropdown(
                                            onTap: () =>
                                                FocusScope.of(context)
                                                    .requestFocus(
                                                    FocusNode()),
                                            onValuePicked: (
                                                Country country) {
                                              print("${country.name}");
                                            },
                                            itemBuilder: (Country country) {
                                              return Row(
                                                children: <Widget>[
                                                  CountryPickerUtils
                                                      .getDefaultFlagImage(
                                                      country),
                                                  Expanded(
                                                    child: Text(
                                                      country.isoCode,
                                                    ),
                                                  ),
                                                ],
                                              );
                                            },
                                            itemHeight: null,
                                            isExpanded: true,
                                            icon: SizedBox(),
                                          )

Does anyone know how to do it? Thanks in advance

5
  • You will have to pass countryFilter argument with India as first item.
    – Rahul
    Dec 27, 2021 at 8:05
  • can you tell me how?
    – CodingBee
    Dec 27, 2021 at 8:07
  • you can refer here
    – gretal
    Dec 27, 2021 at 8:07
  • @CodingBee checked the source code. countryFilter won't work. The plugin doesn't provide comparable where you could have set order of countries.
    – Rahul
    Dec 27, 2021 at 8:13
  • @CodingBee you can raise a ticket on plugin github project or fix it yourself and raise a PR.
    – Rahul
    Dec 27, 2021 at 8:16

1 Answer 1

0

try below code hope its helpful to you. just Set initialValue used country_pickers package here

Your Widget:

CountryPickerDropdown(
    initialValue: 'in',
    itemBuilder: _buildDropdownItem,
    onValuePicked: (Country country) {
         print("${country.name}");
      },
),

Your method:

Widget _buildDropdownItem(Country country) => Container(
        child: Row(
          children: <Widget>[
            CountryPickerUtils.getDefaultFlagImage(country),
            SizedBox(
              width: 8.0,
            ),
            Text("+${country.phoneCode}(${country.isoCode})"),
          ],
        ),
      );

Your result screen-> image

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.