File tree Expand file tree Collapse file tree 3 files changed +73
-2
lines changed
mecury_project/example/flutter_widget_of_the_week/lib Expand file tree Collapse file tree 3 files changed +73
-2
lines changed Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change @@ -27,4 +27,5 @@ export 'week26_position.dart';
2727export 'week27_animated_builder.dart' ;
2828export 'week28_dismissible.dart' ;
2929export 'week29_sizedbox.dart' ;
30- export 'week30_value_listenable_builder.dart' ;
30+ export 'week30_value_listenable_builder.dart' ;
31+ export 'week31_draggable.dart' ;
You can’t perform that action at this time.
0 commit comments