Draggable element with tracking x and y position in flutter. To use a Draggable like this,
1. You’ll need to be able to set the element’s position, something like Positioned and its left,top.
2. Then you’ll need to get the ending coordinates of the drag, using dragDetails from onDragEnd: (dragDetails) { }
Here’s a simple sample to start you off:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | Positioned( left: _x, top: _y, child: Draggable( child: FlutterLogo(size: _logoSize), feedback: FlutterLogo(size: _logoSize), childWhenDragging: Container(), onDragEnd: (dragDetails) { setState(() { _x = dragDetails.offset.dx; // if applicable, don't forget offsets like app/status bar _y = dragDetails.offset.dy - appBarHeight - statusBarHeight; }); }, ), ) |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.