ReorderableListView.builder constructor

const ReorderableListView.builder({
  1. Key? key,
  2. required IndexedWidgetBuilder itemBuilder,
  3. required int itemCount,
  4. @Deprecated('Use the onReorderItem callback instead. ' 'The onReorderItem callback adjusts the newIndex parameter for a removed item at the oldIndex. ' 'This feature was deprecated after v3.41.0-0.0.pre.') ReorderCallback? onReorder,
  5. ReorderCallback? onReorderItem,
  6. void onReorderStart(
    1. int index
    )?,
  7. void onReorderEnd(
    1. int index
    )?,
  8. double? itemExtent,
  9. ItemExtentBuilder? itemExtentBuilder,
  10. Widget? prototypeItem,
  11. ReorderItemProxyDecorator? proxyDecorator,
  12. bool buildDefaultDragHandles = true,
  13. EdgeInsets? padding,
  14. Widget? header,
  15. Widget? footer,
  16. Axis scrollDirection = Axis.vertical,
  17. bool reverse = false,
  18. ScrollController? scrollController,
  19. bool? primary,
  20. ScrollPhysics? physics,
  21. bool shrinkWrap = false,
  22. double anchor = 0.0,
  23. @Deprecated('Use scrollCacheExtent instead. ' 'This feature was deprecated after v3.41.0-0.0.pre.') double? cacheExtent,
  24. ScrollCacheExtent? scrollCacheExtent,
  25. DragStartBehavior dragStartBehavior = DragStartBehavior.start,
  26. ScrollViewKeyboardDismissBehavior? keyboardDismissBehavior,
  27. String? restorationId,
  28. Clip clipBehavior = Clip.hardEdge,
  29. double? autoScrollerVelocityScalar,
  30. ReorderDragBoundaryProvider? dragBoundaryProvider,
  31. MouseCursor? mouseCursor,
})

Creates a reorderable list from widget items that are created on demand.

This constructor is appropriate for list views with a large number of children because the builder is called only for those children that are actually visible.

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

The itemBuilder should always return a non-null widget, and actually create the widget instances when called. Avoid using a builder that returns a previously-constructed widget; if the list view's children are created in advance, or all at once when the ReorderableListView itself is created, it is more efficient to use the ReorderableListView constructor. Even more efficient, however, is to create the instances on demand using this constructor's itemBuilder callback.

This example creates a list using the ReorderableListView.builder constructor. Using the IndexedWidgetBuilder, The list items are built lazily on demand.

link

To create a local project with this code sample, run:
flutter create --sample=material.ReorderableListView.ReorderableListView.builder.1 mysample

See also:

  • ReorderableListView, which allows you to build a reorderable list with all the items passed into the constructor.

Implementation

const ReorderableListView.builder({
  super.key,
  required this.itemBuilder,
  required this.itemCount,
  @Deprecated(
    'Use the onReorderItem callback instead. '
    'The onReorderItem callback adjusts the newIndex parameter for a removed item at the oldIndex. '
    'This feature was deprecated after v3.41.0-0.0.pre.',
  )
  this.onReorder,
  this.onReorderItem,
  this.onReorderStart,
  this.onReorderEnd,
  this.itemExtent,
  this.itemExtentBuilder,
  this.prototypeItem,
  this.proxyDecorator,
  this.buildDefaultDragHandles = true,
  this.padding,
  this.header,
  this.footer,
  this.scrollDirection = Axis.vertical,
  this.reverse = false,
  this.scrollController,
  this.primary,
  this.physics,
  this.shrinkWrap = false,
  this.anchor = 0.0,
  @Deprecated(
    'Use scrollCacheExtent instead. '
    'This feature was deprecated after v3.41.0-0.0.pre.',
  )
  this.cacheExtent,
  this.scrollCacheExtent,
  this.dragStartBehavior = DragStartBehavior.start,
  this.keyboardDismissBehavior,
  this.restorationId,
  this.clipBehavior = Clip.hardEdge,
  this.autoScrollerVelocityScalar,
  this.dragBoundaryProvider,
  this.mouseCursor,
}) : assert(itemCount >= 0),
     assert(
       (itemExtent == null && prototypeItem == null) ||
           (itemExtent == null && itemExtentBuilder == null) ||
           (prototypeItem == null && itemExtentBuilder == null),
       'You can only pass one of itemExtent, prototypeItem and itemExtentBuilder.',
     ),
     assert(
       (onReorderItem != null && onReorder == null) ||
           (onReorderItem == null && onReorder != null),
       'The onReorder callback is obsolete and is replaced by onReorderItem. '
       'Remove the onReorder callback when both callbacks are provided.',
     );