ReorderableGridView class

Ordering children in a Wrap that can be drag and dropped.

Simple way of drag and drop children that were built inside a Wrap.

To enable the possibility of the drag and drop, it's important to build all children inside a Wrap. After that every child is added to the entity GridItemEntity that contains the position and orderId of the build item. When all items are added to new map animatedChildren, the widget is reconstructing the wrap inside a Container. This Container has the same size as the Wrap. Inside the Container, all children are rebuild with a Positioned widget. At the end, the same widget is build without a Wrap but now it's possible to update the positions of the widgets with a drag and drop.

A list of children that are build inside a Wrap.

Using spacing adds a space in vertical direction between children. The default value is 8.

Using runSpacing adds a space in horizontal direction between children. The default value is 8.

enableAnimation is enabling the animation of changing the positions of children after drag and drop. The default value is true.

With enableLongPress you can decide if the user needs a long press to move the item around. The default value is true.

onUpdate always give you the old and new index of the moved children. Make sure to update your list of children that you used to display your data. See more on the example.

Inheritance

Constructors

ReorderableGridView({required List<Widget> children, List<int> lockedChildren = const [], double spacing = 8, double runSpacing = 8, bool enableAnimation = true, bool enableLongPress = true, Duration longPressDelay = kLongPressTimeout, void onUpdate(int oldIndex, int newIndex)?, Key? key})
const

Properties

children List<Widget>
Adding children that should be displayed inside this widget
final
enableAnimation bool
By default animation is enabled when the position of the items changes
final
enableLongPress bool
By default long press is enabled when tapping an item
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
lockedChildren List<int>
final
longPressDelay Duration
By default it has a duration of 500ms before an item can be moved.
final
onUpdate → (void Function(int oldIndex, int newIndex)?)
Every a child changes his position, this function is called.
final
runSpacing double
Spacing between displayed items in vertical direction
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
spacing double
Spacing between displayed items in horizontal direction
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<ReorderableGridView>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited