Flutter 3.41 is live! Check out theFlutter 3.41 blog post!
Drag outside an app
How to drag from an app to another app or the operating system.
You might want to implement drag and drop somewhere in your app.
You have a couple potential approaches that you can take. One directly uses Flutter widgets and the other uses a package (super_drag_and_drop), available onpub.dev.
Create draggable widgets within your app
# If you want to implement drag and drop within your application, you can use theDraggable widget. For insight into this approach, see theDrag a UI element within an app recipe.
An advantage of usingDraggable andDragTarget is that you can supply Dart code to decide whether to accept a drop.
For more information, check out theDraggable widget of the week video.
Implement drag and drop between apps
#If you want to implement drag and drop within your application andalso between your application and another (possibly non-Flutter) app, check out thesuper_drag_and_drop package.
To avoid implementing two styles of drag and drop, one for drags outside of the app and another for dragging inside the app, you can supplylocal data to the package to perform drags within your app.
Another difference between this approach and usingDraggable directly, is that you must tell the package up front what data your app accepts because the platform APIs need a synchronous response, which doesn't allow an asynchronous response from the framework.
An advantage of using this approach is that it works across desktop, mobile,and web.
Unless stated otherwise, the documentation on this site reflects Flutter 3.38.6. Page last updated on 2024-04-04.View source orreport an issue.