@@ -63,27 +63,50 @@ class BoardItemState extends State<BoardItem>
6363 }
6464 }
6565
66+ bool get canStartDragging =>
67+ widget.boardList! .widget.boardView! .widget.isNotSelecting &&
68+ widget.draggable;
69+
6670 void _startDrag (Widget item, BuildContext context) {
67- if (widget.boardList! .widget.boardView != null ) {
68- widget.boardList! .widget.boardView! .onDropItem = _onDropItem;
69- if (widget.boardList! .mounted) {
70- widget.boardList! .setState (() {});
71- }
72- widget.boardList! .widget.boardView! .draggedItemIndex = widget.index;
73- widget.boardList! .widget.boardView! .height = context.size! .height;
74- widget.boardList! .widget.boardView! .draggedListIndex =
75- widget.boardList! .widget.index;
76- widget.boardList! .widget.boardView! .startListIndex =
77- widget.boardList! .widget.index;
78- widget.boardList! .widget.boardView! .startItemIndex = widget.index;
79- widget.boardList! .widget.boardView! .draggedItem = item;
80- if (widget.onStartDragItem != null ) {
81- widget.onStartDragItem !(
82- widget.boardList! .widget.index, widget.index, this );
83- }
84- widget.boardList! .widget.boardView! .run ();
85- if (widget.boardList! .widget.boardView! .mounted) {
86- widget.boardList! .widget.boardView! .setState (() {});
71+ if (canStartDragging) {
72+ RenderBox object = context.findRenderObject () as RenderBox ;
73+ Offset pos = object.localToGlobal (Offset .zero);
74+ RenderBox box = widget.boardList! .context.findRenderObject () as RenderBox ;
75+ Offset listPos = box.localToGlobal (Offset .zero);
76+ widget.boardList! .widget.boardView! .leftListX = listPos.dx;
77+ widget.boardList! .widget.boardView! .topListY = listPos.dy;
78+ widget.boardList! .widget.boardView! .topItemY = pos.dy;
79+ widget.boardList! .widget.boardView! .bottomItemY =
80+ pos.dy + object.size.height;
81+ widget.boardList! .widget.boardView! .bottomListY =
82+ listPos.dy + box.size.height;
83+ widget.boardList! .widget.boardView! .rightListX =
84+ listPos.dx + box.size.width;
85+
86+ widget.boardList! .widget.boardView! .initialX = pos.dx;
87+ widget.boardList! .widget.boardView! .initialY = pos.dy;
88+
89+ if (widget.boardList! .widget.boardView != null ) {
90+ widget.boardList! .widget.boardView! .onDropItem = _onDropItem;
91+ if (widget.boardList! .mounted) {
92+ widget.boardList! .setState (() {});
93+ }
94+ widget.boardList! .widget.boardView! .draggedItemIndex = widget.index;
95+ widget.boardList! .widget.boardView! .height = context.size! .height;
96+ widget.boardList! .widget.boardView! .draggedListIndex =
97+ widget.boardList! .widget.index;
98+ widget.boardList! .widget.boardView! .startListIndex =
99+ widget.boardList! .widget.index;
100+ widget.boardList! .widget.boardView! .startItemIndex = widget.index;
101+ widget.boardList! .widget.boardView! .draggedItem = item;
102+ if (widget.onStartDragItem != null ) {
103+ widget.onStartDragItem !(
104+ widget.boardList! .widget.index, widget.index, this );
105+ }
106+ widget.boardList! .widget.boardView! .run ();
107+ if (widget.boardList! .widget.boardView! .mounted) {
108+ widget.boardList! .widget.boardView! .setState (() {});
109+ }
87110 }
88111 }
89112 }
@@ -105,39 +128,14 @@ class BoardItemState extends State<BoardItem>
105128 }
106129 widget.boardList! .itemStates.insert (widget.index! , this );
107130 return GestureDetector (
108- onTapDown: (otd) {
109- if (widget.draggable) {
110- RenderBox object = context.findRenderObject () as RenderBox ;
111- Offset pos = object.localToGlobal (Offset .zero);
112- RenderBox box =
113- widget.boardList! .context.findRenderObject () as RenderBox ;
114- Offset listPos = box.localToGlobal (Offset .zero);
115- widget.boardList! .widget.boardView! .leftListX = listPos.dx;
116- widget.boardList! .widget.boardView! .topListY = listPos.dy;
117- widget.boardList! .widget.boardView! .topItemY = pos.dy;
118- widget.boardList! .widget.boardView! .bottomItemY =
119- pos.dy + object.size.height;
120- widget.boardList! .widget.boardView! .bottomListY =
121- listPos.dy + box.size.height;
122- widget.boardList! .widget.boardView! .rightListX =
123- listPos.dx + box.size.width;
124-
125- widget.boardList! .widget.boardView! .initialX = pos.dx;
126- widget.boardList! .widget.boardView! .initialY = pos.dy;
127- }
128- },
129- onTapCancel: () {},
130131 onTap: () {
131132 if (widget.onTapItem != null ) {
132133 widget.onTapItem !(widget.boardList! .widget.index, widget.index, this );
133134 }
134135 },
135- onLongPress: () {
136- if (! widget.boardList! .widget.boardView! .widget.isSelecting &&
137- widget.draggable) {
138- _startDrag (widget, context);
139- }
140- },
136+ onHorizontalDragStart: (DragStartDetails _) =>
137+ _startDrag (widget, context),
138+ onVerticalDragStart: (DragStartDetails _) => _startDrag (widget, context),
141139 child: widget.item,
142140 );
143141 }
0 commit comments