Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: Drag and drop with Grid

I want to create a widget where you can add multiple widgets with different sizes and can change their position by using the drag and drop technique. Something like a grid view with drag and drop where you can change the position both horizontally and vertically. While you are dragging the selected widget, other widgets will move around to open up space for it.

Does anyone have any suggestion where to start or are there already some examples that are implementing what I am looking for?

like image 751
koraxis Avatar asked May 09 '18 14:05

koraxis


1 Answers

You can also try this easier one (It doesn't include Feedback)

enter image description here

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(home: Scaffold(body: HomePage()));
  }
}

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  Offset offset = Offset.zero;

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: <Widget>[
        Positioned(
          left: offset.dx,
          top: offset.dy,
          child: GestureDetector(
            onPanUpdate: (details) {
              setState(() {
                offset = Offset(offset.dx + details.delta.dx, offset.dy + details.delta.dy);
              });
            },
            child: Container(width: 100, height: 100, color: Colors.blue),
          ),
        ),
      ],
    );
  }
}
like image 186
CopsOnRoad Avatar answered Nov 03 '22 22:11

CopsOnRoad