update method

Future<T> update(
  1. String endpoint,
  2. T item
)

Implementation

Future<T> update(String endpoint, T item) async {
  final response = await http.put(
    Uri.parse('$baseUrl/$endpoint/${item.id}'),
    headers: {'Content-Type': 'application/json'},
    body: json.encode(item.toJson()),
  );

  if (response.statusCode == 200) {
    final Map<String, dynamic> data = json.decode(response.body);
    return this.instance.fromJson(data);
  } else {
    throw Exception('Erro na chamada de serviço: ${response.statusCode}');
  }
}