updateData static method

Future updateData({
  1. required String url,
  2. required Map<String, dynamic> body,
  3. Map<String, String> header = const {'Content-Type' : 'application/json'},
})

Implementation

static Future<dynamic> updateData(
    {required String url,
    required Map<String, dynamic> body,
    Map<String, String> header = const {
      'Content-Type': 'application/json'
    }}) async {
  try {
    Response response = await put(
      Uri.parse(url),
      body: jsonEncode(body),
      headers: header,
    );
    log('POST status: ${response.statusCode}');
    if (response.statusCode == 200) {
      if (response.body.isNotEmpty) {
        return jsonDecode(response.body);
      }
      return null;
    }
    throw ApiFailedException(msg: 'failed to update the data :(');
  } on ApiFailedException catch (e) {
    log(e.toString());
    return null;
  }
}