-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

AndrewGB
  • 16,126
  • 5
  • 18
  • 49
CodingBee
  • 99
  • 3
  • 7

1 Answers1

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

Ravindra S. Patil
  • 11,757
  • 3
  • 13
  • 40