tryDecodeAds function
Tries to decode a list of advertisements from JSON data.
Returns a list of FastResponseAd objects if the JSON data
is
successfully decoded, otherwise returns null.
Implementation
List<FastResponseAd>? tryDecodeAds(String? data) {
if (data != null) {
try {
final jsonData = json.decode(data);
if (jsonData is List) {
return jsonData
.whereType<Map<String, dynamic>>()
.map((data) => FastResponseAd.fromJson(data))
.toList();
}
} catch (error) {
debugPrint(error.toString());
}
}
return null;
}