getData static method

Future getData({
  1. required String url,
  2. Map<String, String> header = const {},
})

Implementation

static Future<dynamic> getData({
  required String url,
  Map<String, String> header = const {},
}) async {
  try {
    Response response = await get(Uri.parse(url), headers: header);
    log('GET status: ${response.statusCode}');
    if (response.statusCode == 200) {
      if (response.body.isNotEmpty) {
        return jsonDecode(response.body);
      }
      return null;
    }
    throw ApiFailedException(msg: 'failed to get the data :(');
  } on ApiFailedException catch (e) {
    log(e.toString());
    return null;
  }
}