editData method

Future<Map<String, dynamic>> editData(
  1. String endpoint,
  2. Map<String, dynamic> data
)

Implementation

Future<Map<String, dynamic>> editData(
    String endpoint, Map<String, dynamic> data) async {
  final Uri url = Uri.parse('$rootApi$endpoint');

  final response = await http.put(url, body: jsonEncode(data), headers: {
    'Content-Type': 'application/json',
  });

  if (response.statusCode == 200 || response.statusCode == 204) {
    return jsonDecode(response.body) as Map<String, dynamic>;
  } else {
    throw Exception(
        'Failed to edit data. Status Code : ${response.statusCode}');
  }
}