index method

  1. @override
Future<List<Data>> index([
  1. Map<String, dynamic>? params
])
override

Retrieves all resources.

Implementation

@override
Future<List<Data>> index([Map<String, dynamic>? params]) async {
  var url = baseUrl.replace(queryParameters: _buildQuery(params));
  var response = await app.sendUnstreamed('GET', url, _readHeaders);

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

    var v = json.decode(response.body) as List;
    //var r = v.map(deserialize).toList();
    var r = <Data>[];
    for (var element in v) {
      var a = deserialize(element);
      if (a != null) {
        r.add(a);
      }
    }
    _onIndexed.add(r);
    return r;
  } catch (e, st) {
    if (_onIndexed.hasListener) {
      _onIndexed.addError(e, st);
    } else {
      throw failure(response, error: e, stack: st);
    }
  }

  return [];
}