page property

double get page

Returns the current page index.

Implementation

double get page {
  if (_attachedElement == null) return initialPage.toDouble();

  final isHoriz = direction == ScrollDirection.horizontal;

  // calculate page size based on scroll direction and viewport fraction
  final pageSize =
      (isHoriz
          ? _attachedElement!.clientWidth
          : _attachedElement!.clientHeight) *
      viewportFraction;

  // avoid division by zero
  if (pageSize <= 0) return initialPage.toDouble();

  // get current scroll offset
  final currentOffset = isHoriz
      ? _attachedElement!.scrollLeft
      : _attachedElement!.scrollTop;

  // calculate current page index
  return currentOffset / pageSize;
}