create method

  1. @override
Future<Data?> create(
  1. Data? data, [
  2. Map<String, dynamic>? params
])
override

Creates a resource.

Implementation

@override
Future<Data?> create(data, [Map<String, dynamic>? params]) async {
  var url = baseUrl.replace(queryParameters: _buildQuery(params));
  var response =
      await app.sendUnstreamed('POST', url, _writeHeaders, makeBody(data));

  try {
    if (_invalid(response)) {
      if (_onCreated.hasListener) {
        _onCreated.addError(failure(response));
      } else {
        throw failure(response);
      }
    }

    var r = deserialize(json.decode(response.body));
    _onCreated.add(r);
    return r;
  } catch (e, st) {
    if (_onCreated.hasListener) {
      _onCreated.addError(e, st);
    } else {
      throw failure(response, error: e, stack: st);
    }
  }

  return null;
}