Skip to content

Commit 42e646e

Browse files
committed
新增 week 31 draggable demo
1 parent c1c7734 commit 42e646e

File tree

3 files changed

+73
-2
lines changed

3 files changed

+73
-2
lines changed

mecury_project/example/flutter_widget_of_the_week/lib/main.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ class MyApp extends StatelessWidget {
4141
// home: Week27(),
4242
// home: Week28(),
4343
// home: Week29(),
44-
home: Week30(),
44+
// home: Week30(),
45+
home: Week31(),
4546
);
4647
}
4748
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import 'package:flutter/material.dart';
2+
3+
class Week31 extends StatefulWidget {
4+
@override
5+
_Week31State createState() => _Week31State();
6+
}
7+
8+
class _Week31State extends State<Week31> {
9+
Color color = Colors.grey;
10+
11+
@override
12+
Widget build(BuildContext context) {
13+
return Scaffold(
14+
body: Column(
15+
children: <Widget>[
16+
Expanded(
17+
child: Center(
18+
child: Draggable<Color>(
19+
data: Colors.deepPurpleAccent,
20+
feedback: Container(
21+
height: 100,
22+
width: 100,
23+
color: Colors.deepPurpleAccent.withOpacity(0.5),
24+
),
25+
child: Container(
26+
height: 100,
27+
width: 100,
28+
color: Colors.deepPurpleAccent,
29+
),
30+
childWhenDragging: Container(
31+
height: 100,
32+
width: 100,
33+
color: Colors.grey.withOpacity(0.5),
34+
),
35+
),
36+
),
37+
),
38+
Expanded(
39+
child: Center(
40+
child: DragTarget<Color>(
41+
onWillAccept: (color){
42+
return color == Colors.deepPurpleAccent;
43+
},
44+
builder: (context, colors, rejectedData){
45+
print(colors.toString());
46+
return Container(
47+
height: 200,
48+
width: 200,
49+
color: colors.length > 0 ? colors[0] : color,
50+
);
51+
},
52+
onAccept: (color){
53+
setState(() {
54+
this.color = color;
55+
});
56+
},
57+
onLeave: (color){
58+
setState(() {
59+
this.color = color;
60+
});
61+
},
62+
),
63+
),
64+
)
65+
],
66+
),
67+
);
68+
}
69+
}

mecury_project/example/flutter_widget_of_the_week/lib/widget/widgets.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ export 'week26_position.dart';
2727
export 'week27_animated_builder.dart';
2828
export 'week28_dismissible.dart';
2929
export 'week29_sizedbox.dart';
30-
export 'week30_value_listenable_builder.dart';
30+
export 'week30_value_listenable_builder.dart';
31+
export 'week31_draggable.dart';

0 commit comments

Comments
 (0)