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
bf097eec
Commit
bf097eec
authored
Aug 21, 2019
by
Nigel Gott
Committed by
Kate Lovett
Aug 21, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix DragTarget not being rebuilt when a rejected Draggable enters #38786 (#38789)
parent
2e01eef5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
143 additions
and
2 deletions
+143
-2
drag_target.dart
packages/flutter/lib/src/widgets/drag_target.dart
+5
-2
draggable_test.dart
packages/flutter/test/widgets/draggable_test.dart
+138
-0
No files found.
packages/flutter/lib/src/widgets/drag_target.dart
View file @
bf097eec
...
...
@@ -524,9 +524,12 @@ class _DragTargetState<T> extends State<DragTarget<T>> {
_candidateAvatars
.
add
(
avatar
);
});
return
true
;
}
else
{
setState
(()
{
_rejectedAvatars
.
add
(
avatar
);
});
return
false
;
}
_rejectedAvatars
.
add
(
avatar
);
return
false
;
}
void
didLeave
(
_DragAvatar
<
dynamic
>
avatar
)
{
...
...
packages/flutter/test/widgets/draggable_test.dart
View file @
bf097eec
...
...
@@ -972,6 +972,144 @@ void main() {
Offset
(
secondLocation
.
dx
,
secondLocation
.
dy
-
firstLocation
.
dy
)));
});
testWidgets
(
'Drag and drop - DragTarget rebuilds with and without rejected data when a rejected draggable enters and leaves'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Column
(
children:
<
Widget
>[
const
Draggable
<
int
>(
data:
1
,
child:
Text
(
'Source'
),
feedback:
Text
(
'Dragging'
),
),
DragTarget
<
int
>(
builder:
(
BuildContext
context
,
List
<
int
>
data
,
List
<
dynamic
>
rejects
)
{
return
Container
(
height:
100.0
,
child:
rejects
.
isNotEmpty
?
const
Text
(
'Rejected'
)
:
const
Text
(
'Target'
),
);
},
onWillAccept:
(
int
data
)
=>
false
,
),
],
),
));
expect
(
find
.
text
(
'Dragging'
),
findsNothing
);
expect
(
find
.
text
(
'Target'
),
findsOneWidget
);
expect
(
find
.
text
(
'Rejected'
),
findsNothing
);
final
Offset
firstLocation
=
tester
.
getTopLeft
(
find
.
text
(
'Source'
));
final
TestGesture
gesture
=
await
tester
.
startGesture
(
firstLocation
,
pointer:
7
);
await
tester
.
pump
();
expect
(
find
.
text
(
'Dragging'
),
findsOneWidget
);
expect
(
find
.
text
(
'Target'
),
findsOneWidget
);
expect
(
find
.
text
(
'Rejected'
),
findsNothing
);
final
Offset
secondLocation
=
tester
.
getCenter
(
find
.
text
(
'Target'
));
await
gesture
.
moveTo
(
secondLocation
);
await
tester
.
pump
();
expect
(
find
.
text
(
'Dragging'
),
findsOneWidget
);
expect
(
find
.
text
(
'Target'
),
findsNothing
);
expect
(
find
.
text
(
'Rejected'
),
findsOneWidget
);
await
gesture
.
moveTo
(
firstLocation
);
await
tester
.
pump
();
expect
(
find
.
text
(
'Dragging'
),
findsOneWidget
);
expect
(
find
.
text
(
'Target'
),
findsOneWidget
);
expect
(
find
.
text
(
'Rejected'
),
findsNothing
);
});
testWidgets
(
'Drag and drop - Can drag and drop over a non-accepting target multiple times'
,
(
WidgetTester
tester
)
async
{
int
numberOfTimesOnDraggableCanceledCalled
=
0
;
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Column
(
children:
<
Widget
>[
Draggable
<
int
>(
data:
1
,
child:
const
Text
(
'Source'
),
feedback:
const
Text
(
'Dragging'
),
onDraggableCanceled:
(
Velocity
velocity
,
Offset
offset
)
{
numberOfTimesOnDraggableCanceledCalled
++;
},
),
DragTarget
<
int
>(
builder:
(
BuildContext
context
,
List
<
int
>
data
,
List
<
dynamic
>
rejects
)
{
return
Container
(
height:
100.0
,
child:
rejects
.
isNotEmpty
?
const
Text
(
'Rejected'
)
:
const
Text
(
'Target'
),
);
},
onWillAccept:
(
int
data
)
=>
false
,
),
],
),
));
expect
(
find
.
text
(
'Dragging'
),
findsNothing
);
expect
(
find
.
text
(
'Target'
),
findsOneWidget
);
expect
(
find
.
text
(
'Rejected'
),
findsNothing
);
final
Offset
firstLocation
=
tester
.
getTopLeft
(
find
.
text
(
'Source'
));
final
TestGesture
gesture
=
await
tester
.
startGesture
(
firstLocation
,
pointer:
7
);
await
tester
.
pump
();
expect
(
find
.
text
(
'Dragging'
),
findsOneWidget
);
expect
(
find
.
text
(
'Target'
),
findsOneWidget
);
expect
(
find
.
text
(
'Rejected'
),
findsNothing
);
final
Offset
secondLocation
=
tester
.
getCenter
(
find
.
text
(
'Target'
));
await
gesture
.
moveTo
(
secondLocation
);
await
tester
.
pump
();
expect
(
find
.
text
(
'Dragging'
),
findsOneWidget
);
expect
(
find
.
text
(
'Target'
),
findsNothing
);
expect
(
find
.
text
(
'Rejected'
),
findsOneWidget
);
await
gesture
.
up
();
await
tester
.
pump
();
expect
(
find
.
text
(
'Dragging'
),
findsNothing
);
expect
(
find
.
text
(
'Target'
),
findsOneWidget
);
expect
(
find
.
text
(
'Rejected'
),
findsNothing
);
expect
(
numberOfTimesOnDraggableCanceledCalled
,
1
);
// Drag and drop the Draggable onto the Target a second time.
final
TestGesture
secondGesture
=
await
tester
.
startGesture
(
firstLocation
,
pointer:
7
);
await
tester
.
pump
();
expect
(
find
.
text
(
'Dragging'
),
findsOneWidget
);
expect
(
find
.
text
(
'Target'
),
findsOneWidget
);
expect
(
find
.
text
(
'Rejected'
),
findsNothing
);
await
secondGesture
.
moveTo
(
secondLocation
);
await
tester
.
pump
();
expect
(
find
.
text
(
'Dragging'
),
findsOneWidget
);
expect
(
find
.
text
(
'Target'
),
findsNothing
);
expect
(
find
.
text
(
'Rejected'
),
findsOneWidget
);
await
secondGesture
.
up
();
await
tester
.
pump
();
expect
(
numberOfTimesOnDraggableCanceledCalled
,
2
);
expect
(
find
.
text
(
'Dragging'
),
findsNothing
);
expect
(
find
.
text
(
'Target'
),
findsOneWidget
);
expect
(
find
.
text
(
'Rejected'
),
findsNothing
);
});
testWidgets
(
'Drag and drop - onDragCompleted not called if dropped on non-accepting target'
,
(
WidgetTester
tester
)
async
{
final
List
<
int
>
accepted
=
<
int
>[];
bool
onDragCompletedCalled
=
false
;
...
...
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