Drag And Drop App
Complete Code For Drag And Drop App In Flutter
main.dart
import 'package:flutter/material.dart'; void main(){ runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar( backgroundColor: Colors.lightGreen, title: Text("Drag And Drop App"), ), body: MyHomePage(), ), ); } } class MyHomePage extends StatefulWidget { MyHomePage({Key key}) : super(key: key); @override _MyHomePageState createState() => _MyHomePageState(); } class _MyHomePageState extends State<MyHomePage> { double width = 100.0, height = 100.0; Offset position ; @override void initState() { super.initState(); position = Offset(0.0, height - 20); } @override Widget build(BuildContext context) { return Stack( children: <Widget>[ Positioned( left: position.dx, top: position.dy - height + 20, child: Draggable( child: Container( width: width, height: height, color: Colors.orange, child: Center(child: Text("Drag", style: Theme.of(context).textTheme.headline,),), ), feedback: Container( child: Center( child: Text("Drag", style: Theme.of(context).textTheme.headline,),), color: Colors.lightGreen[300], width: width, height: height, ), onDraggableCanceled: (Velocity velocity, Offset offset){ setState(() => position = offset); }, ), ), ], ); } }