ReorderableListBuilder<T> constructor

const ReorderableListBuilder<T>({
  1. Key? key,
  2. Axis scrollDirection = Axis.vertical,
  3. bool reverse = false,
  4. ScrollController? controller,
  5. bool? primary,
  6. ScrollPhysics? physics,
  7. bool shrinkWrap = false,
  8. EdgeInsetsGeometry? padding,
  9. List<Widget>? top,
  10. List<Widget>? insert,
  11. int insertPosition = 0,
  12. List<Widget>? bottom,
  13. double? itemExtent,
  14. required List<T> source,
  15. required List<Widget>? builder(
    1. BuildContext context,
    2. T item,
    3. int index
    ),
  16. required void onReorder(
    1. int oldPosition,
    2. int newPosition,
    3. T item,
    4. List<T> reordered,
    ),
  17. double? cacheExtent,
  18. Object keyBuilder(
    1. T item
    )?,
  19. bool listenWhenListenable = true,
  20. DragStartBehavior dragStartBehavior = DragStartBehavior.start,
  21. ScrollViewKeyboardDismissBehavior keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual,
  22. String? restorationId,
  23. Clip clipBehavior = Clip.hardEdge,
})

You can configure reorderable lists in a similar fashion to ListBuilder.

Data is passed to source and each element is generated by builder.

By defining onReorder, a callback can be specified when the order is changed, and the actual data can be changed.

If top is set, the top elements are lined up before the source elements are lined up.

If bottom is set, the elements of bottom are lined up after the elements of source are lined up.

When insert is set, insert is inserted at the position of insertPosition in source.

If listenWhenListenable is true, ListenableListener will be wrapped around each element if source inherits Listenable. Therefore, each element of source is monitored individually, and if any element is updated, only that element is updated in the drawing.

ListBuilderと同じような形で順番変更可能なリストを構成することができます。

sourceにデータを渡し、builderで各要素の生成を行います。

onReorderを定義することで順番が変更されたときのコールバックを指定することができ、実データの変更を行うことが可能です。

topを設定するとsourceの要素を並べる前にtopの要素を並べます。

bottomを設定するとsourceの要素を並べた後にbottomの要素を並べます。

insertを設定するとsourceinsertPositionの位置にinsertが挿入されます。

listenWhenListenabletrueになっている場合、sourceListenableを継承している場合ListenableListenerが各要素にラップされます。 そのため、sourceの各要素をそれぞれ監視し、いずれかの要素が更新された場合その要素のみ描画が更新されます。

Implementation

const ReorderableListBuilder({
  super.key,
  this.scrollDirection = Axis.vertical,
  this.reverse = false,
  this.controller,
  this.primary,
  this.physics,
  this.shrinkWrap = false,
  this.padding,
  this.top,
  this.insert,
  this.insertPosition = 0,
  this.bottom,
  this.itemExtent,
  required this.source,
  required this.builder,
  required this.onReorder,
  this.cacheExtent,
  this.keyBuilder,
  this.listenWhenListenable = true,
  this.dragStartBehavior = DragStartBehavior.start,
  this.keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual,
  this.restorationId,
  this.clipBehavior = Clip.hardEdge,
})  : _topLength = top.length,
      _length = top.length + source.length + bottom.length + insert.length,
      _topSourcelength = top.length + source.length + insert.length;