Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/const/page_item_const.dart
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,9 @@ const PAGE_ITEMS = [
"img": PageImage.FLUTTER_OPEN,
"click": PageName.ANIM_OPACITY,
},
{
"title": PageName.INTER_DRAG,
"img": PageImage.FLUTTER_OPEN,
"click": PageName.INTER_DRAG,
},
];
1 change: 1 addition & 0 deletions lib/const/page_name_const.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@ class PageName {
static const ANIM_WIDGET = "AnimatedWidget";
static const ANIM_PYH_MODEL = "PyhModel";
static const ANIM_OPACITY = "OpacityPage";
static const INTER_DRAG = "Draggable";
}
1 change: 1 addition & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class FlutterOpenApp extends StatelessWidget {
PageName.ANIM_WIDGET: (context) => AnimWidgetPage(),
PageName.ANIM_PYH_MODEL: (context) => PyhModelPage(),
PageName.ANIM_OPACITY: (context) => AnimOpacityPage(),
PageName.INTER_DRAG: (context) => DraggablePage(),
},
);
}
Expand Down
1 change: 1 addition & 0 deletions lib/page/_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ export 'layoutsingle/_layout_single.dart';
export 'muti/_muti.dart';
export 'assets/_assets.dart';
export 'anim/_anim.dart';
export 'interation/_interaction.dart';
80 changes: 80 additions & 0 deletions lib/page/interation/DraggablePage.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
///
/// Created by NieBin on 2019/6/11
/// Github: https://github.com/nb312
/// Email: niebin312@gmail.com
///
import "package:flutter/material.dart";
import "package:flutter_widgets/const/_const.dart";

class DraggablePage extends StatefulWidget {
@override
_DragState createState() => _DragState();
}

class _DragState extends State<DraggablePage> {
String _value = "";

Widget _draggable(String _data) => Draggable<String>(
child: Text(
"$_data",
style: TextStyle(color: RED_LIGHT, fontSize: 30),
),
feedback: Text(
"$_data",
style: TextStyle(color: BLUE_DEEP),
),
childWhenDragging: Container(),
maxSimultaneousDrags: 1,
onDragCompleted: () {
print("Complete.");
},
onDragStarted: () {
print("Start");
},
onDraggableCanceled: (v, off) {
print("Cancel");
},
data: _data,
);

Widget _target() => DragTarget<String>(
builder: (context, List<String> candidateData, rejectedData) =>
Container(
constraints: BoxConstraints.expand(height: 100),
color: GREEN,
alignment: Alignment.center,
child: Text(
candidateData.length > 0 ? candidateData[0] : _value,
style: TextStyle(color: Colors.white, fontSize: 30),
),
),
onAccept: (value) {
print("Accept value= $value");
_value = value;
},
onLeave: (value) {
print("leave = $value");
},
onWillAccept: (value) {
print("Will Accept: value = $value");
return true;
},
);

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(PageName.INTER_DRAG),
),
body: Column(
children: <Widget>[
Text(" You should drag the text and put it into the green area,"
"then you can see the text changed."),
_draggable("Hello"),
_draggable("World"),
_target(),
],
));
}
}
6 changes: 6 additions & 0 deletions lib/page/interation/_interaction.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
///
/// Created by NieBin on 2019/6/11
/// Github: https://github.com/nb312
/// Email: niebin312@gmail.com
///
export "DraggablePage.dart";