showCountryWithSearch method

Flexible showCountryWithSearch(
  1. PhoneInputController logic
)

Implementation

Flexible showCountryWithSearch(PhoneInputController logic) {
  return Flexible(
    child: ListView.builder(
      shrinkWrap: true,
      itemCount:
          logic.filterCountry.isEmpty && logic.searchCountryString.isEmpty
              ? Countries.countryList.length
              : logic.filterCountry.length,
      itemBuilder: (BuildContext context, int index) {
        late Country country;
        if (logic.filterCountry.isEmpty) {
          country = Country.fromJson(
            Countries.countryList[index],
          );
        } else {
          country = logic.filterCountry[index];
        }

        return CountryItemWidget(
          country: country,
          onChangeCountry: (context, newCountry) {
            if (onChangedCountry == null) {
              logic.changeSelectCountry(
                newCountry: country,
                context: context,
              );
            } else {
              onChangedCountry!(newCountry);
            }
          },
        );
      },
    ),
  );
}