FullCoin.fromJson constructor

FullCoin.fromJson(
  1. Map<String, dynamic> json
)

Implementation

FullCoin.fromJson(Map<String, dynamic> json)
    : json = json,
      image = json['image'],
      currentPrice = StaticHelpers.checkDouble(json['current_price'], -1.0),
      marketCap = StaticHelpers.checkDouble(json['market_cap'], -1.0),
      marketCapRank = json['market_cap_rank'],
      fullyDilutedValuation =
          StaticHelpers.checkDouble(json['fully_diluted_valuation'], -1.0),
      circulatingSupply =
          StaticHelpers.checkDouble(json['circulating_supply'], -1.0),
      maxSupply = StaticHelpers.checkDouble(json['max_supply'], -1.0),
      totalSupply = StaticHelpers.checkDouble(json['total_supply'], -1.0),
      totalVolume = StaticHelpers.checkDouble(json['total_volume'], -1.0),
      high24h = StaticHelpers.checkDouble(json['high_24h'], null),
      low24h = StaticHelpers.checkDouble(json['low_24h'], null),
      priceChange24h =
          StaticHelpers.checkDouble(json['price_change_24h'], null),
      priceChangePercentage24h = StaticHelpers.checkDouble(
          json['price_change_percentage_24h'], null),
      marketCapChange24h =
          StaticHelpers.checkDouble(json['market_cap_change_24h'], null),
      marketCapChangePercentage24h = StaticHelpers.checkDouble(
          json['market_cap_percentage_change_24h'], null),
      priceChangePercentage1hInCurrency = StaticHelpers.checkDouble(
          json['price_change_percentage_1h_in_currency'], null),
      priceChangePercentage24hInCurrency = StaticHelpers.checkDouble(
          json['price_change_percentage_24h_in_currency'], null),
      priceChangePercentage7dInCurrency = StaticHelpers.checkDouble(
          json['price_change_percentage_7d_in_currency'], null),
      priceChangePercentage14dInCurrency = StaticHelpers.checkDouble(
          json['price_change_percentage_14d_in_currency'], null),
      priceChangePercentage30dInCurrency = StaticHelpers.checkDouble(
          json['price_change_percentage_30d_in_currency'], null),
      priceChangePercentage200dInCurrency = StaticHelpers.checkDouble(
          json['price_change_percentage_200d_in_currency'], null),
      priceChangePercentage1yInCurrency = StaticHelpers.checkDouble(
          json['price_change_percentage_1y_in_currency'], null),
      atl = StaticHelpers.checkDouble(json['atl'], null),
      ath = StaticHelpers.checkDouble(json['ath'], null),
      atlChangePercentage =
          StaticHelpers.checkDouble(json['atl_change_percentage'], null),
      athChangePercentage =
          StaticHelpers.checkDouble(json['ath_change_percentage'], null),
      super.fromJson(json) {
  athDate =
      (json['ath_date'] != null) ? DateTime.tryParse(json['ath_date']) : null;
  atlDate =
      (json['atl_date'] != null) ? DateTime.tryParse(json['atl_date']) : null;
  lastUpdated = (json['last_updated'] != null)
      ? DateTime.tryParse(json['last_updated'])
      : null;

  //decode sparkline
  List<double> sparkline7d = [];
  if (json['sparkline_in_7d'] != null &&
      json['sparkline_in_7d']['price'] != null) {
    for (double price in json['sparkline_in_7d']['price'])
      sparkline7d.add(price);
  }
  this.sparkline7d = sparkline7d;
}