patch method

Future<void> patch(
  1. String path, {
  2. Map<String, String>? headers,
  3. Map<String, dynamic>? body,
  4. String? contentType,
  5. bool withLoading = true,
  6. dynamic fromJson(
    1. Map<String, dynamic>
    )?,
})

PATCH request to API

Perform a PATCH request to API with specific path and a body. You can send the headers, contentType and a fromJson method to parse the result json to a specific object.

Implementation

Future<void> patch(
  String path, {
  Map<String, String>? headers,
  Map<String, dynamic>? body,
  String? contentType,
  bool withLoading = true,
  dynamic Function(Map<String, dynamic>)? fromJson,
}) async {
  if (withLoading) emit(RestState.loading());
  try {
    final result = await _restDataSource.patch(
      path,
      body: body,
      contentType: contentType,
      fromJson: fromJson,
      headers: headers,
    );
    emit(
      RestState.loaded(
        data: result['data'],
        headers: result['headers'] as Map<String, List<String>>,
        lastPath: path,
        timestamp: DateTime.now().toIso8601String(),
      ),
    );
  } on ResponseException catch (e) {
    emit(RestState.error(humanMessage: e.humanMessage, message: e.message));
  }
}