forked from md-siam/widget_of_the_day
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraggable.dart
52 lines (48 loc) · 1.35 KB
/
draggable.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import 'package:flutter/material.dart';
class MyDraggable extends StatefulWidget {
const MyDraggable({Key? key}) : super(key: key);
@override
State<MyDraggable> createState() => _MyDraggableState();
}
class _MyDraggableState extends State<MyDraggable> {
Color color = Colors.black;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Draggable')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
DragTarget<Color>(
onAccept: (data) => setState(() => color = data),
builder: (context, _, __) => Container(
color: color,
width: 200,
height: 200,
),
),
Draggable<Color>(
data: Colors.green,
child: Container(
color: Colors.green,
width: 200,
height: 200,
),
feedback: Container(
color: Colors.orange,
width: 200,
height: 200,
),
childWhenDragging: Container(
color: Colors.red,
width: 200,
height: 200,
),
),
],
),
),
);
}
}