getCoinData method

Future<CoinGeckoResult<Coin?>> getCoinData({
  1. required String id,
  2. bool localization = true,
  3. bool tickers = true,
  4. bool marketData = true,
  5. bool communityData = true,
  6. bool developerData = true,
  7. bool sparkline = false,
})

Get current data (name, price, market, ... including exchange tickers) for a coin.

id sets coin id.

localization sets whether to include all localized languages in response. Default is true.

tickers sets whether to include tickers data. Default is true.

marketData sets whether to include market data. Default is true.

communityData sets whether to include community data. Default is true.

developerData sets whether to include developer data. Default is true.

sparkline sets whether to include sparkline. Default is false.

Query path: /coins/{id}

Implementation

Future<CoinGeckoResult<Coin?>> getCoinData({
  required String id,
  bool localization = true,
  bool tickers = true,
  bool marketData = true,
  bool communityData = true,
  bool developerData = true,
  bool sparkline = false,
}) async {
  final response = await _client.dio.get(
    '/coins/$id',
    queryParameters: {
      'localization': localization,
      'tickers': tickers,
      'market_data': marketData,
      'community_data': communityData,
      'developer_data': developerData,
      'sparkline': sparkline,
    },
  );
  if (response.statusCode == 200) {
    final data = Coin.fromJson(response.data);
    return CoinGeckoResult(data);
  } else {
    return CoinGeckoResult(
      null,
      errorCode: response.statusCode ?? null,
      errorMessage: '${response.statusMessage} - ${response.data.toString()}',
      isError: true,
    );
  }
}