fetchGeoInfo method
Implementation
@override
Future<Map<String, dynamic>> fetchGeoInfo(Uri url) async {
// Try the caller-supplied URL first, then fall back to secondary provider.
var data = await _fetchWithRetry(url);
String countryCode = '';
if (data != null) {
// ipinfo.io uses 'country' for 2-letter code
countryCode = (data['country'] as String?) ?? '';
} else {
data = await _fetchWithRetry(Uri.parse(_fallbackUrl));
if (data != null) {
// infoip.io uses 'country_short' for 2-letter code
countryCode = (data['country_short'] as String?) ?? '';
}
}
if (data == null) {
return {};
}
_cachedIpCountryCode = countryCode.toUpperCase();
// Filter out ignored keys
final filteredMap = Map<String, dynamic>.fromEntries(
data.entries.where((entry) => !ignoredKeys.contains(entry.key)),
);
return filteredMap;
}