getBytes method

Future<Uint8List> getBytes({
  1. bool usingCache = false,
})

Implementation

Future<Uint8List> getBytes({bool usingCache = false}) async {
  Uint8List response;
  if (!usingCache) {
    if (method.body.isNotEmpty || method.files.isNotEmpty) {
      response = await method.request(getResponseBytes: true) as Uint8List;
    } else {
      response =
          await method.requestJson(getResponseBytes: true) as Uint8List;
    }
  } else {
    Uint8List? cachedResponse =
        await CacheResponseManager().getCachedResponseBytes(method);
    if (cachedResponse == null) {
      throw errorModel(cachedResponse, "NO-CACHED", ExpectType.list);
    }
    response = cachedResponse;
  }

  try {
    return response;
  } catch (e) {
    throw errorModel(response, e.toString(), ExpectType.bytes);
  }
}