put method

Future<Map<String, dynamic>> put(
  1. String url, {
  2. String? data,
  3. Map<String, dynamic>? header,
})

Implementation

Future<Map<String, dynamic>> put(String url,
    {String? data, Map<String, dynamic>? header}) async {
  // Await the http get response, then decode the json-formatted response.
  var response;
  Map<String, String> headers = Map<String, String>();
  header?.forEach((k, v) => headers[k] = v);

  if (data!=null && data.isNotEmpty) {
    headers["content-length"] = data.length.toString();

    response = await http.put(Uri.parse(url), body: data, headers: headers);
  } else {
    response = await http.put(Uri.parse(url));
  }
  if (response.statusCode == 200) {
    var jsonResponse = json.decode(response.body);
    print('Response: $jsonResponse.');
    return jsonResponse;
  } else {
    print('Request failed with status: ${response.statusCode}.');
    return Map();
  }
}