showCountryCodePickerBottomSheet function

Future<Country?> showCountryCodePickerBottomSheet({
  1. required BuildContext context,
  2. List<Country> countries = const [],
  3. Country? initiallySelected,
  4. List<String> favorite = const [],
  5. CountryPickerStyle style = const CountryPickerStyle(),
})

Present the modal bottom sheet and return the selected country. If countries is empty, uses a small built-in demo list.

  • initiallySelected pre-selects a country in the list.
  • favorite pins countries (ISO2 or dial codes) as quick chips.

Implementation

Future<Country?> showCountryCodePickerBottomSheet({
  required BuildContext context,
  List<Country> countries = const [],
  Country? initiallySelected,
  List<String> favorite = const [],
  CountryPickerStyle style = const CountryPickerStyle(),
}) {
  final all = (countries.isEmpty) ? _defaultCountries : normalizeCountries(countries);

  return showModalBottomSheet<Country>(
    context: context,
    isScrollControlled: true,
    useSafeArea: true,
    backgroundColor: Theme.of(context).colorScheme.surface,
    shape: RoundedRectangleBorder(
      borderRadius: BorderRadius.vertical(top: Radius.circular(style.cornerRadius)),
    ),
    builder: (ctx) {
      return _CountryPickerSheet(
        all: all,
        selected: initiallySelected ?? (all.isNotEmpty ? all.first : null),
        favorite: favorite,
        style: style,
      );
    },
  );
}