getAPI method

Future<BaseResponse> getAPI(
  1. String path,
  2. dynamic data, {
  3. bool hasHeader = true,
  4. bool hasDomain = true,
  5. int timeout = 20,
})

Implementation

Future<BaseResponse> getAPI(String path, data, {bool hasHeader = true, bool hasDomain = true, int timeout = 20}) async {
  final baseResponse = BaseResponse();
  try {
    http.Response response;
    final prefs = await SharedPreferences.getInstance();
    final header = await _getHeader(hasAuthen: hasHeader && prefs.containsKey(keyIsLogin) && prefs.getBool(keyIsLogin)!);
    response = await httpClient.get(Uri.parse((hasDomain ? baseUrl : '') + path), headers: header).timeout(Duration(seconds: timeout));
    baseResponse.fromJson(jsonDecode(response.body), data);
  } catch (e) {
    return _responseError(baseResponse, e);
  }
  return baseResponse;
}