getDefaultCountry function
This function returns an user's current country. User's sim country code is matched with the ones in the list. If there is no sim in the device, first country in the list will be returned.
Implementation
Future<Country> getDefaultCountry(BuildContext context) async {
final list = await getCountries(context);
var currentCountry;
try {
final countryCode = await FlutterSimCountryCode.simCountryCode;
currentCountry =
list.firstWhere((element) => element.countryCode == countryCode);
} catch (e) {
currentCountry = list.first;
}
return currentCountry;
}