reorderCountries static method

void reorderCountries(
  1. List<Country> countries,
  2. String? userCountryCode
)

Reorder countries alphabetically, bring user's locale country to top.

Implementation

static void reorderCountries(
  List<Country> countries,
  String? userCountryCode,
) {
  countries.sort((Country a, Country b) {
    if (a.offTag == userCountryCode) {
      return -1;
    }
    if (b.offTag == userCountryCode) {
      return 1;
    }
    return a.localizedName.compareTo(b.localizedName);
  });
}