getCryptocurrencies method

  1. @override
Future<List<Cryptocurrency>> getCryptocurrencies()
override

Implementation

@override
Future<List<Cryptocurrency>> getCryptocurrencies() async {
  final String response = await DataFetcher.fetchUrlData(url);
  var cryptoList = <Cryptocurrency>[];

  List<dynamic> cryptomap = jsonDecode(response);
  for (final item in cryptomap) {
    var crypto = Cryptocurrency(
      id: item['id'],
      name: item['name'],
      symbol: item['symbol'],
      image: item['image'],
      currentPriceUSD: item['current_price'],
      marketCap: item['market_cap'],
      marketCapRank: item['market_cap_rank'],
      totalVolume: item['total_volume'],
      priceChange24h: item['price_change_24h'],
      totalSupply: item['total_supply'] ?? item['circulating_supply'],
    );
    cryptoList.add(crypto);
  }
  return cryptoList;
}