deleteMethod method

Future<HttpResponseMTPL> deleteMethod(
  1. String url, {
  2. dynamic data,
  3. Map<String, String>? headers,
})

Implementation

Future<HttpResponseMTPL> deleteMethod(String url,
    {dynamic data, Map<String, String>? headers}) async {
  if ((await checkConnection()) != ConnectivityResult.none) {
    headers = await getSessionData(headers ?? {});

    http.Response response = await http.delete(Uri.parse(endPoint + url),
        body: data, headers: headers);
    // return jsonDecode(utf8.decode(response.bodyBytes));
    return HttpResponseMTPL(
      statusCode: response.statusCode,
      data: jsonDecode(utf8.decode(response.bodyBytes)),
    );
  } else {
    if (noInternetScreen != null && context != null) {
      await Navigator.push(
        context!,
        MaterialPageRoute(builder: (context) => noInternetScreen!),
      );
      return deleteMethod(url, data: data, headers: headers);
    }
    return Future.error(Strings.noInternet);
  }
}