PageView.builder constructor

PageView.builder({
  1. Key? key,
  2. Axis scrollDirection = Axis.horizontal,
  3. bool reverse = false,
  4. PageController? controller,
  5. ScrollPhysics? physics,
  6. bool pageSnapping = true,
  7. ValueChanged<int>? onPageChanged,
  8. required NullableIndexedWidgetBuilder itemBuilder,
  9. ChildIndexGetter? findChildIndexCallback,
  10. int? itemCount,
  11. DragStartBehavior dragStartBehavior = DragStartBehavior.start,
  12. bool allowImplicitScrolling = false,
  13. String? restorationId,
  14. Clip clipBehavior = Clip.hardEdge,
  15. HitTestBehavior hitTestBehavior = HitTestBehavior.opaque,
  16. ScrollBehavior? scrollBehavior,
  17. bool padEnds = true,
})

Creates a scrollable list that works page by page using widgets that are created on demand.

This constructor is appropriate for page views with a large (or infinite) number of children because the builder is called only for those children that are actually visible.

Providing a non-null itemCount lets the PageView compute the maximum scroll extent.

itemBuilder will be called only with indices greater than or equal to zero and less than itemCount.

It is legal for itemBuilder to return null. If it does, the scroll view will stop calling itemBuilder, even if it has yet to reach itemCount. By returning null, the ScrollPosition.maxScrollExtent will not be accurate unless the user has reached the end of the ScrollView. This can also cause the Scrollbar to grow as the user scrolls.

For more accurate ScrollMetrics, consider specifying itemCount.

The findChildIndexCallback corresponds to the SliverChildBuilderDelegate.findChildIndexCallback property. If null, a child widget may not map to its existing RenderObject when the order of children returned from the children builder changes. This may result in state-loss. This callback needs to be implemented if the order of the children may change at a later time.

If allowImplicitScrolling is true, the PageView will participate in accessibility scrolling more like a ListView, where implicit scroll actions will move to the next page rather than into the contents of the PageView.

Implementation

PageView.builder({
  super.key,
  this.scrollDirection = Axis.horizontal,
  this.reverse = false,
  this.controller,
  this.physics,
  this.pageSnapping = true,
  this.onPageChanged,
  required NullableIndexedWidgetBuilder itemBuilder,
  ChildIndexGetter? findChildIndexCallback,
  int? itemCount,
  this.dragStartBehavior = DragStartBehavior.start,
  this.allowImplicitScrolling = false,
  this.restorationId,
  this.clipBehavior = Clip.hardEdge,
  this.hitTestBehavior = HitTestBehavior.opaque,
  this.scrollBehavior,
  this.padEnds = true,
}) : childrenDelegate = SliverChildBuilderDelegate(
       itemBuilder,
       findChildIndexCallback: findChildIndexCallback,
       childCount: itemCount,
     );