getDefaultCountry function

Future<Country> getDefaultCountry()

This function returns an user's current country. User's sim country code is matched with the ones in the list. if there's no sim country code it will return first country on the list

Implementation

Future<Country> getDefaultCountry() async {
  final list = getCountries();
  try {
    final countryCode = await FlutterSimCountryCode.simCountryCode;
    if (countryCode == null) {
      return list.first;
    }
    return list.firstWhere((element) =>
        element.countryCode.toLowerCase() == countryCode.toLowerCase());
  } catch (e) {
    return list.first;
  }
}