showCountryWithSearch method

Flexible showCountryWithSearch(
  1. PhoneInputController ctrl
)

Implementation

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

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