page property Null safety

double? page

The current page displayed in the controlled PreloadPageView.

There are circumstances that this PreloadPageController can't know the current page. Reading page will throw an AssertionError in the following cases:

  1. No PreloadPageView is currently using this PreloadPageController. Once a PreloadPageView starts using this PreloadPageController, the new page position will be derived:
  1. More than one PreloadPageView using the same PreloadPageController.

The hasClients property can be used to check if a PreloadPageView is attached prior to accessing page.

Implementation

double? get page {
  assert(
    positions.isNotEmpty,
    'PageController.page cannot be accessed before a PageView is built with it.',
  );
  assert(
    positions.length == 1,
    'The page property cannot be read when multiple PageViews are attached to '
    'the same PageController.',
  );
  final _PagePosition position = this.position as _PagePosition;
  return position.page;
}