Issue
This is what I use for Android and iOS
final List<Locale> systemLocales = WidgetsBinding.instance!.window.locales;
String countryCode = WidgetsBinding.instance!.window.locale.countryCode;
On Android it works fine:
But on iOS the country code comes null:
Solution
Solution just for iOS if we cannot get the country code:
Future<String> _getCountryCode() async {
final link = Uri.parse('http://ip-api.com/json');
final jsonEncoded = await http.read(link);
final Map jsonDecoded = json.decode(jsonEncoded);
return jsonDecoded['countryCode'];
}
Answered By – Dani
Answer Checked By – Willingham (FlutterFixes Volunteer)