isRevealed method
bool
isRevealed(
- int index, {
- required ScrollExtent scrollExtent,
- VisibilityStrategy strategy = VisibilityStrategy.tolerance,
- double tolerance = 0.1,
- bool shouldNormalized = true,
- bool shouldConvert = false,
inherited
if index
is revealed in its closest ancestor RenderSliver.
typically, index
must have been observed before checking isRevealed
.
strategy
is used to determine the threshold of which index
should be regarded as revealed/visible.
shouldNormalized
indicates if we need to normalizeIndex
into a valid range.
ScrollExtent is the current scroll extent built from ScrollPosition to indicate the current min/max scroll extent and pixels.
if shouldConvert
is true, it would try to use targetToRenderIndex
to convert index
to its render index.
shouldConvert
is always false when using internally for jumpToIndex and animateToIndex.
Note that isRevealed
should only be used when firstLayoutFinished
is completed and isActive
Implementation
bool isRevealed(
int index, {
required ScrollExtent scrollExtent,
VisibilityStrategy strategy = VisibilityStrategy.tolerance,
double tolerance = 0.1,
bool shouldNormalized = true,
bool shouldConvert = false,
}) {
assert(isActive && firstLayoutFinished);
index = shouldConvert ? targetToRenderIndex?.call(index) ?? index : index;
final validIndex = shouldNormalized ? normalizeIndex(index) : index;
final itemScrollExtent = getItemScrollExtent(validIndex);
final itemSize = getItemSize(validIndex);
if (!renderVisible || itemScrollExtent == null || itemSize == null) {
return false;
}
final leadingOffset = itemScrollExtent.getLeadingOffset(origin!.offset);
final double trailingOffset = itemScrollExtent.getTrailingOffset(
leadingOffset,
axis: axis,
size: itemSize,
);
final trailingEdge = getTrailingEdgeFromScroll(scrollExtent);
return strategy.handle(
leadingOffset,
trailingOffset,
leadingEdge: scrollExtent.current,
trailingEdge: trailingEdge,
maxScrollExtent: scrollExtent.max,
tolerance: tolerance,
);
}