diff --git a/docs/resources/ui/widgets/built-in-widgets/draggable.md b/docs/resources/ui/widgets/built-in-widgets/draggable.md index f3e4b71c..61f9e33b 100644 --- a/docs/resources/ui/widgets/built-in-widgets/draggable.md +++ b/docs/resources/ui/widgets/built-in-widgets/draggable.md @@ -1,28 +1,50 @@ --- +slug: draggable +title: Draggable and DragTarget tags: [Base Elements] +description: Learn how to build drag-and-drop interactions with the Draggable and DragTarget widgets in FlutterFlow. --- -# Draggable + DragTarget +# Draggable and DragTarget -The Draggable widget is used to make a widget that can be dragged and dropped to a different location within the app. It allows users to interact with the app by moving an item using touch gestures or a mouse. The DragTarget widget is used in conjunction with the Draggable widget to specify where a dragged item can be dropped. It creates a region that can accept the data carried by the Draggable widget. +The **Draggable** and **DragTarget** widgets let users move items from one place to another in your app. Use **Draggable** for the item that can be moved and **DragTarget** for the area where it can be dropped. For example, users can sort items, move tasks between columns, or drag products into a cart. -When an item is dragged over a DragTarget, the DragTarget has the opportunity to determine whether it can accept the item. If it accepts, it can then trigger actions such as updating the app's state to reflect the change. + -For example, in a shopping cart app, you could use these widgets together to allow users to add items to their cart by dragging and dropping them onto a cart icon. +## How Draggable and DragTarget Work -## Adding Draggable and DragTarget Widgets +A drag-and-drop interaction has three parts: -Let's see how to add a drag-and-drop functionality by building an example that allows users to put only plants on the shelf. Here's how it looks: +1. The user starts dragging the child of a **Draggable** widget. +2. The Draggable carries its configured data **Value**. +3. A **DragTarget** with a matching data **Type** receives the value and runs the configured actions. + +The data type controls compatibility between the widgets. The value identifies the dragged item and can be checked before the app updates its state. + +## 1. Adding a Draggable Widget + +1. Add a **Draggable** widget from the [Widget Palette](../../../../intro/ff-ui/widget-palette.md). +2. Add the widget that users should drag, such as an **Image**, **Container**, or **Card**, as its child. + +:::tip +The child of a Draggable widget must have its **Width** and **Height** set explicitly. +::: + +### Setting the Draggable Data + +- **Type:** Defines the kind of data carried by the widget. This must match the **Type** configured on the intended DragTarget. +- **Value:** Contains the data passed to the DragTarget. The value can be static or set from a variable. + +For simple interactions, the value can be a string or number that identifies the item. Use a custom data type when the target needs multiple related values, such as a product ID, name, and price.