Draggable and DragTarget in one

Viewed 132

How can you make a "cell" both Draggable and a DragTarget, like on a chess board?

In this sample code onWillAccept is never hit:

                DragTarget<String>(
                  builder: (
                      BuildContext context,
                      List<dynamic> accepted,
                      List<dynamic> rejected,
                      ) {
                    return Draggable(
                      data: "data",
                      childWhenDragging: Container(),
                      feedback: Text("I am dragging"),
                      child: Text("Drag me"),
                    );
                  },
                  onWillAccept: (data) {
                    return true;
                  },
                  onAccept: (data) {},
                )

Update Found this this one - having DragTarget build the Draggable is the way to go. You just need to wrap the Draggable in a Container.

0 Answers
Related