getCountries method
Future<BuiltList<Country> ?>
getCountries({
- dynamic onErrorTryCache = false,
- dynamic firstCache = false,
Implementation
Future<BuiltList<Country>?> getCountries(
{onErrorTryCache: false, firstCache: false}) async {
if (firstCache && cacheIsNotEmpty) return Future.value(_cache);
var response = await http.get(Uri.parse(_endpointUrl));
if (response.statusCode == 200) {
var countries = standardSerializers.deserialize(jsonDecode(response.body),
specifiedType: FullType(BuiltList, [FullType(Country)]))
as BuiltList<Country>?;
_cache = countries;
return _cache;
} else if (onErrorTryCache == true && cacheIsNotEmpty) {
return _cache;
} else {
return Future.error(response);
}
}