put method

Future put({
  1. String? baseUrl,
  2. String? authorization,
  3. required String path,
  4. dynamic data,
  5. bool skipJsonDecode = false,
})

Implementation

Future<dynamic> put({
  String? baseUrl,
  String? authorization,
  required String path,
  var data,
  bool skipJsonDecode = false,
}) async {
  http_package.Response? response;
  try {
    baseUrl ??= Api.getAPIBaseUrls();
    final url = Uri.parse((baseUrl) + path);
    log('PUT---$url');
    log('PUT---DATA---$data');

    response = await http_package.put(
      url,
      body: data == null ? null : jsonEncode(data),
      headers: header(authorization),
    );
    log('Status Code:${response.statusCode}');
    log('Response : ${response.body}');
    log('isFailure : ${isFailure(response.statusCode)}');
    if (skipJsonDecode || isFailure(response.statusCode)) {
      return response.body;
    }
    if (response.body.isEmpty) {
      return <String, dynamic>{};
    }
    return json.decode(response.body);
  } catch (exception) {
    log(exception.toString());
    return null;
  }
}