searchFor method

Future<CoinGeckoResult<SearchResults?>> searchFor({
  1. required String query,
})

Search for coins, categories and markets listed on CoinGecko ordered by largest Market Cap first.

Query: /search

Implementation

Future<CoinGeckoResult<SearchResults?>> searchFor({
  required String query,
}) async {
  final response = await _dio.get(
    '/search',
    queryParameters: {
      'query': query,
    },
  );
  if (response.statusCode == 200) {
    final searchResults = SearchResults.fromJson(response.data);
    return CoinGeckoResult(searchResults);
  } else {
    return CoinGeckoResult(
      null,
      errorCode: response.statusCode ?? null,
      errorMessage: '${response.statusMessage} - ${response.data.toString()}',
      isError: true,
    );
  }
}