getAt method

Stream<T> getAt(
  1. int index
)

Implementation

Stream<T> getAt(final int index) async* {
  if (index < _list.length) {
    if (!_list[index].loaded) {
      final QueryBuilder<T> queryBuilder = QueryBuilder<T>.copy(_query)
        ..whereEqualTo(
            keyVarObjectId, _list[index].object.get<String>(keyVarObjectId))
        ..setLimit(1);
      final ParseResponse response = await queryBuilder.query<T>();
      if (_list.isEmpty) {
        yield* _createStreamError<T>(
            ParseError(message: 'ParseLiveList: _list is empty'));
        return;
      }
      if (response.success) {
        _list[index].object = response.results?.first;
      } else {
        ParseError? error = response.error;
        if (error != null) yield* _createStreamError<T>(error);
        return;
      }
    }
//    just for testing
//    await Future<void>.delayed(const Duration(seconds: 2));
    yield _list[index].object;
    yield* _list[index].stream;
  }
}