onDragging method
Implementation
void onDragging(DragUpdateDetails details) {
if (!draggable) return;
if (_itemGlobalPosition == null) {
final renderBox = key.currentContext?.findRenderObject() as RenderBox?;
_itemGlobalPosition = renderBox?.localToGlobal(Offset.zero);
_itemGlobalPosition ??= Offset.zero;
}
_itemPosition += details.delta;
_itemPosition = Offset(
_itemPosition.dx.clamp(
-_itemGlobalPosition!.dx,
_screenSize.width - _itemGlobalPosition!.dx - _widgetSize.width,
),
_itemPosition.dy.clamp(
-_itemGlobalPosition!.dy,
_screenSize.height - _itemGlobalPosition!.dy - _widgetSize.height,
),
);
setState(() {});
}