putMethod method

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

Implementation

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

    http.Response response = await http.put(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 putMethod(url, data: data, headers: headers);
    }
    return Future.error(Strings.noInternet);
  }
}