call static method

Future call({
  1. required String apiKey,
  2. required String url,
  3. required String dataKey,
})

Implementation

static Future<dynamic> call({
  required String apiKey,
  required String url,
  required String dataKey,
}) async {
  url = "$_baseUrl$url&apiKey=$apiKey";
  debugPrint(url);
  try {
    var response = await http.get(Uri.parse(url));
    Map<String, dynamic> responseJson = json.decode(response.body);
    if (responseJson["status"].toString().toLowerCase() == "ok") {
      return responseJson[dataKey];
    }
    return Future.error(
      ApiError(
        responseJson["code"],
        responseJson["message"],
      ),
    );
  } catch (e) {
    return Future.error(ApiError("unknown", e.toString()));
  }
}