Skip to content

Commit 1d70b23

Browse files
committed
add the Draggable,DragTarget widget.
1 parent a91997b commit 1d70b23

File tree

6 files changed

+94
-0
lines changed

6 files changed

+94
-0
lines changed

lib/const/page_item_const.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,4 +252,9 @@ const PAGE_ITEMS = [
252252
"img": PageImage.FLUTTER_OPEN,
253253
"click": PageName.ANIM_OPACITY,
254254
},
255+
{
256+
"title": PageName.INTER_DRAG,
257+
"img": PageImage.FLUTTER_OPEN,
258+
"click": PageName.INTER_DRAG,
259+
},
255260
];

lib/const/page_name_const.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,5 @@ class PageName {
5555
static const ANIM_WIDGET = "AnimatedWidget";
5656
static const ANIM_PYH_MODEL = "PyhModel";
5757
static const ANIM_OPACITY = "OpacityPage";
58+
static const INTER_DRAG = "Draggable";
5859
}

lib/main.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class FlutterOpenApp extends StatelessWidget {
6969
PageName.ANIM_WIDGET: (context) => AnimWidgetPage(),
7070
PageName.ANIM_PYH_MODEL: (context) => PyhModelPage(),
7171
PageName.ANIM_OPACITY: (context) => AnimOpacityPage(),
72+
PageName.INTER_DRAG: (context) => DraggablePage(),
7273
},
7374
);
7475
}

lib/page/_page.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ export 'layoutsingle/_layout_single.dart';
3636
export 'muti/_muti.dart';
3737
export 'assets/_assets.dart';
3838
export 'anim/_anim.dart';
39+
export 'interation/_interaction.dart';
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
///
2+
/// Created by NieBin on 2019/6/11
3+
/// Github: https://github.com/nb312
4+
/// Email: niebin312@gmail.com
5+
///
6+
import "package:flutter/material.dart";
7+
import "package:flutter_widgets/const/_const.dart";
8+
9+
class DraggablePage extends StatefulWidget {
10+
@override
11+
_DragState createState() => _DragState();
12+
}
13+
14+
class _DragState extends State<DraggablePage> {
15+
String _value = "";
16+
17+
Widget _draggable(String _data) => Draggable<String>(
18+
child: Text(
19+
"$_data",
20+
style: TextStyle(color: RED_LIGHT, fontSize: 30),
21+
),
22+
feedback: Text(
23+
"$_data",
24+
style: TextStyle(color: BLUE_DEEP),
25+
),
26+
childWhenDragging: Container(),
27+
maxSimultaneousDrags: 1,
28+
onDragCompleted: () {
29+
print("Complete.");
30+
},
31+
onDragStarted: () {
32+
print("Start");
33+
},
34+
onDraggableCanceled: (v, off) {
35+
print("Cancel");
36+
},
37+
data: _data,
38+
);
39+
40+
Widget _target() => DragTarget<String>(
41+
builder: (context, List<String> candidateData, rejectedData) =>
42+
Container(
43+
constraints: BoxConstraints.expand(height: 100),
44+
color: GREEN,
45+
alignment: Alignment.center,
46+
child: Text(
47+
candidateData.length > 0 ? candidateData[0] : _value,
48+
style: TextStyle(color: Colors.white, fontSize: 30),
49+
),
50+
),
51+
onAccept: (value) {
52+
print("Accept value= $value");
53+
_value = value;
54+
},
55+
onLeave: (value) {
56+
print("leave = $value");
57+
},
58+
onWillAccept: (value) {
59+
print("Will Accept: value = $value");
60+
return true;
61+
},
62+
);
63+
64+
@override
65+
Widget build(BuildContext context) {
66+
return Scaffold(
67+
appBar: AppBar(
68+
title: Text(PageName.INTER_DRAG),
69+
),
70+
body: Column(
71+
children: <Widget>[
72+
Text(" You should drag the text and put it into the green area,"
73+
"then you can see the text changed."),
74+
_draggable("Hello"),
75+
_draggable("World"),
76+
_target(),
77+
],
78+
));
79+
}
80+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
///
2+
/// Created by NieBin on 2019/6/11
3+
/// Github: https://github.com/nb312
4+
/// Email: niebin312@gmail.com
5+
///
6+
export "DraggablePage.dart";

0 commit comments

Comments
 (0)