Skip to content

Commit

Permalink
新增 week 31 draggable demo
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadaski committed Dec 30, 2019
1 parent c1c7734 commit 42e646e
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class MyApp extends StatelessWidget {
// home: Week27(),
// home: Week28(),
// home: Week29(),
home: Week30(),
// home: Week30(),
home: Week31(),
);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import 'package:flutter/material.dart';

class Week31 extends StatefulWidget {
@override
_Week31State createState() => _Week31State();
}

class _Week31State extends State<Week31> {
Color color = Colors.grey;

@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: <Widget>[
Expanded(
child: Center(
child: Draggable<Color>(
data: Colors.deepPurpleAccent,
feedback: Container(
height: 100,
width: 100,
color: Colors.deepPurpleAccent.withOpacity(0.5),
),
child: Container(
height: 100,
width: 100,
color: Colors.deepPurpleAccent,
),
childWhenDragging: Container(
height: 100,
width: 100,
color: Colors.grey.withOpacity(0.5),
),
),
),
),
Expanded(
child: Center(
child: DragTarget<Color>(
onWillAccept: (color){
return color == Colors.deepPurpleAccent;
},
builder: (context, colors, rejectedData){
print(colors.toString());
return Container(
height: 200,
width: 200,
color: colors.length > 0 ? colors[0] : color,
);
},
onAccept: (color){
setState(() {
this.color = color;
});
},
onLeave: (color){
setState(() {
this.color = color;
});
},
),
),
)
],
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ export 'week26_position.dart';
export 'week27_animated_builder.dart';
export 'week28_dismissible.dart';
export 'week29_sizedbox.dart';
export 'week30_value_listenable_builder.dart';
export 'week30_value_listenable_builder.dart';
export 'week31_draggable.dart';

0 comments on commit 42e646e

Please sign in to comment.