around method
- K? key,
- C? cursor,
- int count
override
Fetches the Page around the provided key
or cursor
.
If neither key
nor cursor
is provided, then fetches the first Page.
Implementation
@override
Future<Page<T, C>> around(K? key, C? cursor, int count) async {
_reset(around: key, count: count);
final int edgesBefore = _list.length;
final List<T> edges = await _page();
final bool fulfilled =
fulfilledWhenNone ||
(_hasFirst && _hasLast) ||
edges.length - edgesBefore >= count ~/ 2;
Log.debug(
'around($key, $count) -> $fulfilled(${edges.length}) cuz ($fulfilledWhenNone || ($_hasFirst && $_hasLast) || ${edges.length} - $edgesBefore >= ${count ~/ 2}), hasNext: ${!_hasLast}, hasPrevious: ${!_hasFirst}',
'$runtimeType',
);
_ensureLimits();
final bool zeroed = fulfilledWhenNone && edges.isEmpty;
return Page(
fulfilled ? edges : [],
PageInfo(
hasNext: !_hasLast && !zeroed,
hasPrevious: !_hasFirst && !zeroed,
startCursor: _firstCursor,
endCursor: _lastCursor,
),
);
}