ReorderableGridView, ReorderableSliverGridView and ReorderableWrapperWidget now expose an additional callback onDragUpdate (similarly to the already existing onDragStart callback). The callback is invoked by the _onDragUpdate method of the ReorderableGridWidgetMixin. It receives the index of the dragged item, the current position of the pointer in the global coordinate system and the relative offset since the last invocation of the callback.
Why is this change useful?
By exposing the onDragUpdate callback, it becomes possible to react to position changes of the dragged widget and to track the pointer position while dragging.
Will this change break any existing code?
No. This change introduces an additional non-required nullable callback attribute to ReorderableGridView, ReorderableSliverGridView and ReorderableWrapperWidget. For any existing code, the new callback will automatically be set to null, which causes the callback not to be called inside ReorderableGridWidgetMixin._onDragUpdate and therefore does not change the existing behavior.
Example
An example use of the new callback is to detect if the pointer position of a dragged widget is within a predefined drop region. This allows us to mimic some of the behavior of Flutter's built-in DropTarget class.
In the example below, a grid item can be dropped onto a predefined drop region to delete it from the grid. To provide visual feedback, if the item will be deleted if dropped, it is necessary to check, if the pointer is inside the drop region while the item is being dragged. The new callback allows us to perform this check every time the position of the item being dragged changes.
What changed?
ReorderableGridView
,ReorderableSliverGridView
andReorderableWrapperWidget
now expose an additional callbackonDragUpdate
(similarly to the already existingonDragStart
callback). The callback is invoked by the_onDragUpdate
method of theReorderableGridWidgetMixin
. It receives the index of the dragged item, the current position of the pointer in the global coordinate system and the relative offset since the last invocation of the callback.Why is this change useful?
By exposing the
onDragUpdate
callback, it becomes possible to react to position changes of the dragged widget and to track the pointer position while dragging.Will this change break any existing code?
No. This change introduces an additional non-required nullable callback attribute to
ReorderableGridView
,ReorderableSliverGridView
andReorderableWrapperWidget
. For any existing code, the new callback will automatically be set tonull
, which causes the callback not to be called insideReorderableGridWidgetMixin._onDragUpdate
and therefore does not change the existing behavior.Example
An example use of the new callback is to detect if the pointer position of a dragged widget is within a predefined drop region. This allows us to mimic some of the behavior of Flutter's built-in DropTarget class.
In the example below, a grid item can be dropped onto a predefined drop region to delete it from the grid. To provide visual feedback, if the item will be deleted if dropped, it is necessary to check, if the pointer is inside the drop region while the item is being dragged. The new callback allows us to perform this check every time the position of the item being dragged changes.
https://user-images.githubusercontent.com/37301927/209568774-8546497a-3c06-4c09-b06b-eec694e09f84.mp4