Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
ea3c3f53
Commit
ea3c3f53
authored
Oct 15, 2016
by
Adam Barth
Committed by
GitHub
Oct 15, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Draggable.onDragStarted (#6343)
Fixes #6084
parent
034d2fcd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
2 deletions
+19
-2
drag_target.dart
packages/flutter/lib/src/widgets/drag_target.dart
+10
-1
draggable_test.dart
packages/flutter/test/widget/draggable_test.dart
+9
-1
No files found.
packages/flutter/lib/src/widgets/drag_target.dart
View file @
ea3c3f53
...
...
@@ -75,6 +75,7 @@ class Draggable<T> extends StatefulWidget {
this
.
dragAnchor
:
DragAnchor
.
child
,
this
.
affinity
,
this
.
maxSimultaneousDrags
,
this
.
onDragStarted
,
this
.
onDraggableCanceled
})
:
super
(
key:
key
)
{
assert
(
child
!=
null
);
...
...
@@ -127,6 +128,9 @@ class Draggable<T> extends StatefulWidget {
/// dragged at a time.
final
int
maxSimultaneousDrags
;
/// Called when the draggable starts being dragged.
final
VoidCallback
onDragStarted
;
/// Called when the draggable is dropped without being accepted by a [DragTarget].
final
DraggableCanceledCallback
onDraggableCanceled
;
...
...
@@ -164,6 +168,7 @@ class LongPressDraggable<T> extends Draggable<T> {
Offset
feedbackOffset:
Offset
.
zero
,
DragAnchor
dragAnchor:
DragAnchor
.
child
,
int
maxSimultaneousDrags
,
VoidCallback
onDragStarted
,
DraggableCanceledCallback
onDraggableCanceled
})
:
super
(
key:
key
,
...
...
@@ -174,6 +179,7 @@ class LongPressDraggable<T> extends Draggable<T> {
feedbackOffset:
feedbackOffset
,
dragAnchor:
dragAnchor
,
maxSimultaneousDrags:
maxSimultaneousDrags
,
onDragStarted:
onDragStarted
,
onDraggableCanceled:
onDraggableCanceled
);
...
...
@@ -227,7 +233,7 @@ class _DraggableState<T> extends State<Draggable<T>> {
setState
(()
{
_activeCount
+=
1
;
});
return
new
_DragAvatar
<
T
>(
final
_DragAvatar
<
T
>
avatar
=
new
_DragAvatar
<
T
>(
overlay:
Overlay
.
of
(
context
,
debugRequiredFor:
config
),
data:
config
.
data
,
initialPosition:
position
,
...
...
@@ -242,6 +248,9 @@ class _DraggableState<T> extends State<Draggable<T>> {
});
}
);
if
(
config
.
onDragStarted
!=
null
)
config
.
onDragStarted
();
return
avatar
;
}
@override
...
...
packages/flutter/test/widget/draggable_test.dart
View file @
ea3c3f53
...
...
@@ -8,6 +8,7 @@ import 'package:flutter/material.dart';
void
main
(
)
{
testWidgets
(
'Drag and drop - control test'
,
(
WidgetTester
tester
)
async
{
List
<
int
>
accepted
=
<
int
>[];
int
dragStartedCount
=
0
;
await
tester
.
pumpWidget
(
new
MaterialApp
(
home:
new
Column
(
...
...
@@ -15,7 +16,10 @@ void main() {
new
Draggable
<
int
>(
data:
1
,
child:
new
Text
(
'Source'
),
feedback:
new
Text
(
'Dragging'
)
feedback:
new
Text
(
'Dragging'
),
onDragStarted:
()
{
++
dragStartedCount
;
},
),
new
DragTarget
<
int
>(
builder:
(
BuildContext
context
,
List
<
int
>
data
,
List
<
dynamic
>
rejects
)
{
...
...
@@ -33,6 +37,7 @@ void main() {
expect
(
find
.
text
(
'Source'
),
findsOneWidget
);
expect
(
find
.
text
(
'Dragging'
),
findsNothing
);
expect
(
find
.
text
(
'Target'
),
findsOneWidget
);
expect
(
dragStartedCount
,
0
);
Point
firstLocation
=
tester
.
getCenter
(
find
.
text
(
'Source'
));
TestGesture
gesture
=
await
tester
.
startGesture
(
firstLocation
,
pointer:
7
);
...
...
@@ -42,6 +47,7 @@ void main() {
expect
(
find
.
text
(
'Source'
),
findsOneWidget
);
expect
(
find
.
text
(
'Dragging'
),
findsOneWidget
);
expect
(
find
.
text
(
'Target'
),
findsOneWidget
);
expect
(
dragStartedCount
,
1
);
Point
secondLocation
=
tester
.
getCenter
(
find
.
text
(
'Target'
));
await
gesture
.
moveTo
(
secondLocation
);
...
...
@@ -51,6 +57,7 @@ void main() {
expect
(
find
.
text
(
'Source'
),
findsOneWidget
);
expect
(
find
.
text
(
'Dragging'
),
findsOneWidget
);
expect
(
find
.
text
(
'Target'
),
findsOneWidget
);
expect
(
dragStartedCount
,
1
);
await
gesture
.
up
();
await
tester
.
pump
();
...
...
@@ -59,6 +66,7 @@ void main() {
expect
(
find
.
text
(
'Source'
),
findsOneWidget
);
expect
(
find
.
text
(
'Dragging'
),
findsNothing
);
expect
(
find
.
text
(
'Target'
),
findsOneWidget
);
expect
(
dragStartedCount
,
1
);
});
testWidgets
(
'Drag and drop - dragging over button'
,
(
WidgetTester
tester
)
async
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment