jumpToIndex method
bool
jumpToIndex(
- int index, {
- double alignment = 0.0,
- EdgeInsets padding = EdgeInsets.zero,
- BuildContext? sliverContext,
- bool isFixedHeight = false,
Jumps immediately to the item at the given index without animation.
The alignment determines where the item should be positioned in the viewport
(0.0 = top/left, 0.5 = center, 1.0 = bottom/right).
Returns true if successful, false if no observer controller is attached
or the index is out of bounds.
Example:
cubit.jumpToIndex(10);
cubit.jumpToIndex(0, alignment: 0.5); // Center the item
Implementation
bool jumpToIndex(
int index, {
double alignment = 0.0,
EdgeInsets padding = EdgeInsets.zero,
BuildContext? sliverContext,
bool isFixedHeight = false,
}) {
// Validate index
final items = currentItems;
if (index < 0 || index >= items.length) {
_logger.w('jumpToIndex: index $index out of bounds (0-${items.length - 1})');
return false;
}
try {
if (_listObserverController != null) {
_listObserverController!.jumpTo(
index: index,
alignment: alignment,
padding: padding,
sliverContext: sliverContext,
isFixedHeight: isFixedHeight,
);
_logger.d('Jumped to index $index');
return true;
}
if (_gridObserverController != null) {
_gridObserverController!.jumpTo(
index: index,
alignment: alignment,
padding: padding,
sliverContext: sliverContext,
isFixedHeight: isFixedHeight,
);
_logger.d('Jumped to index $index (grid)');
return true;
}
_logger.w('jumpToIndex: no observer controller attached');
return false;
} catch (e, stackTrace) {
_logger.e('jumpToIndex failed', error: e, stackTrace: stackTrace);
return false;
}
}