saveCountries method
Save countries to cache
Implementation
Future<void> saveCountries(Map<String, Country> countries) async {
try {
final prefs = await SharedPreferences.getInstance();
final jsonList = countries.values
.map((country) => country.toJson())
.toList();
await prefs.setString(_cacheKey, json.encode(jsonList));
await prefs.setInt(_timestampKey, DateTime.now().millisecondsSinceEpoch);
} catch (e) {
print('Failed to save countries to cache: $e');
}
}