0

I've provide the code. So the dragable widget is in the drawer and the drag target is in the home screen. But when I drag the container to put it in the drag target(home screen) the drawer doesn't close

If anyone have the full code that's working just like I discribe plz feel free to share cuz I think there's a lot of people trying to do this as well

 `Drawer(
  child: Column(children: [
    Padding(
      padding: const EdgeInsets.only(top: 100.0),
      child: Draggable(
        child: Container(
          color: Colors.red,
          width: 250,
          height: 100,
        ),
        feedback: Container(
          color: Colors.green,
          width: 250,
          height: 100,
        ),
        childWhenDragging: Container(
          color: Colors.grey,
          width: 250,
          height: 100,
        ),
      ),
    ),
  ]),
);

FloatingActionButton(
                  onPressed: () {
                    Scaffold.of(context).openDrawer();
                  },
                  child: const Icon(
                    Icons.add,
                    color: Colors.white,
                    size: 29,
                  ),
                  backgroundColor: Colors.redAccent,
                  elevation: 0,
                ),`

this is what I want it to look like

when I create a drawer and put container and wrap with drag-able widget then I put a drag target inside the screen But when I try to drag it the drawer doesn’t close.So if you have any idea how to close the drawer when widget is drag plz answer down below

It'sPhil
  • 61
  • 1
  • 2
  • 11
  • You might wanna post some code but if there is a ondrag function you can call Navigator.pop to close the drawer – DEFL Apr 21 '22 at 09:59
  • I've provide the code. So the dragable widget is in the drawer and the drag target is in the home screen. But when I drag the container to put it in the drag target(home screen) the drawer doesn't close – It'sPhil Apr 30 '22 at 06:25
  • The Draggable class provides a function called onDragStart if you place Navigator.pop in there the drawer will close once the drag starts. https://api.flutter.dev/flutter/widgets/Draggable/onDragStarted.html – DEFL Apr 30 '22 at 10:50

1 Answers1

0

The Class Draggable provides a function called onDragStarted. If you place Navigator.pop in there it will close the drawer once the drag starts

Drawer(
  child: Column(children: [
    Padding(
      padding: const EdgeInsets.only(top: 100.0),
      child: Draggable(
        //This function should close the drawer
        onDragStarted: () {
          Navigator.pop(context);
        },
        child: Container(
          color: Colors.red,
          width: 250,
          height: 100,
        ),
        feedback: Container(
          color: Colors.green,
          width: 250,
          height: 100,
        ),
        childWhenDragging: Container(
          color: Colors.grey,
          width: 250,
          height: 100,
        ),
      ),
    ),
  ]),
);

FloatingActionButton(
    onPressed: () {
       Scaffold.of(context).openDrawer();
     },
      child: const Icon(
             cons.add,
                color: Colors.white,
                size: 29,
              ),
              backgroundColor: Colors.redAccent,
              elevation: 0,
       ),
DEFL
  • 907
  • 7
  • 20