httpPut function

Future<Response> httpPut(
  1. Client client,
  2. String url, {
  3. dynamic header,
  4. dynamic body,
  5. List<InterceptorContract>? interceptor,
  6. bool? isLogging,
  7. bool? includeHeader,
  8. List<String>? headersToCheck,
})

Implementation

Future<Response> httpPut(Client client, String url,
    {header,
    body,
    List<InterceptorContract>? interceptor,
    bool? isLogging,
    bool? includeHeader,
    List<String>? headersToCheck}) async {
  client = addInterceptor(isLogging, interceptor ?? [], client);

  bool result = await InternetConnectionChecker().hasConnection;
  var database = DBService();

  if (result) {
    await database.addRequest(type: "put", url: url);
    var response = client.put(
      Uri.parse(url),
    );

    await database.addResponse(
        type: 'put', url: url, body: response, header: header);
    return response;
  } else {
    var responseRow = await database.getResponse(url);
    if (responseRow['response_body'] != null) {
      if (includeHeader == true && headersToCheck?.isNotEmpty == true) {
        if (headersToCheck?.contains(responseRow['response_header']) == false) {
          return Response("Bad Response: header does not match", 400);
        } else {
          return Response(responseRow['response_body'], 200);
        }
      } else {
        return Response(responseRow['response_body'], 200);
      }
    } else {
      return Response("No Internet", 404);
    }
  }
}