read method

  1. @override
Future<Data?> read(
  1. Id id, [
  2. Map<String, dynamic>? params
])
override

Retrieves the desired resource.

Implementation

@override
Future<Data?> read(id, [Map<String, dynamic>? params]) async {
  var pa = _p.join(baseUrl.path, id.toString());
  print(pa);
  var url = baseUrl.replace(
      path: _p.join(baseUrl.path, id.toString()),
      queryParameters: _buildQuery(params));

  var response = await app.sendUnstreamed('GET', url, _readHeaders);

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

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

  return null;
}