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
98067a65
Unverified
Commit
98067a65
authored
Feb 02, 2021
by
David Chen
Committed by
GitHub
Feb 02, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow long press delay duration for LongPressDraggable to be adjustable (#74592)
parent
11609d11
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
1 deletion
+74
-1
drag_target.dart
packages/flutter/lib/src/widgets/drag_target.dart
+7
-1
draggable_test.dart
packages/flutter/test/widgets/draggable_test.dart
+67
-0
No files found.
packages/flutter/lib/src/widgets/drag_target.dart
View file @
98067a65
...
...
@@ -398,6 +398,7 @@ class LongPressDraggable<T extends Object> extends Draggable<T> {
VoidCallback
?
onDragCompleted
,
this
.
hapticFeedbackOnStart
=
true
,
bool
ignoringFeedbackSemantics
=
true
,
this
.
delay
=
kLongPressTimeout
,
})
:
super
(
key:
key
,
child:
child
,
...
...
@@ -419,9 +420,14 @@ class LongPressDraggable<T extends Object> extends Draggable<T> {
/// Whether haptic feedback should be triggered on drag start.
final
bool
hapticFeedbackOnStart
;
/// The duration that a user has to press down before a long press is registered.
///
/// Defaults to [kLongPressTimeout].
final
Duration
delay
;
@override
DelayedMultiDragGestureRecognizer
createRecognizer
(
GestureMultiDragStartCallback
onStart
)
{
return
DelayedMultiDragGestureRecognizer
()
return
DelayedMultiDragGestureRecognizer
(
delay:
delay
)
..
onStart
=
(
Offset
position
)
{
final
Drag
?
result
=
onStart
(
position
);
if
(
result
!=
null
&&
hapticFeedbackOnStart
)
...
...
packages/flutter/test/widgets/draggable_test.dart
View file @
98067a65
...
...
@@ -2452,6 +2452,73 @@ void main() {
expect
(
onDragStartedCalled
,
isTrue
);
});
testWidgets
(
'Custom long press delay for LongPressDraggable'
,
(
WidgetTester
tester
)
async
{
bool
onDragStartedCalled
=
false
;
await
tester
.
pumpWidget
(
MaterialApp
(
home:
LongPressDraggable
<
int
>(
data:
1
,
delay:
const
Duration
(
seconds:
2
),
child:
const
Text
(
'Source'
),
feedback:
const
Text
(
'Dragging'
),
onDragStarted:
()
{
onDragStartedCalled
=
true
;
},
),
));
expect
(
find
.
text
(
'Source'
),
findsOneWidget
);
expect
(
find
.
text
(
'Dragging'
),
findsNothing
);
expect
(
onDragStartedCalled
,
isFalse
);
final
Offset
firstLocation
=
tester
.
getCenter
(
find
.
text
(
'Source'
));
await
tester
.
startGesture
(
firstLocation
,
pointer:
7
);
await
tester
.
pump
();
expect
(
find
.
text
(
'Source'
),
findsOneWidget
);
expect
(
find
.
text
(
'Dragging'
),
findsNothing
);
expect
(
onDragStartedCalled
,
isFalse
);
// Halfway into the long press duration.
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(
find
.
text
(
'Source'
),
findsOneWidget
);
expect
(
find
.
text
(
'Dragging'
),
findsNothing
);
expect
(
onDragStartedCalled
,
isFalse
);
// Long press draggable should be showing.
await
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(
find
.
text
(
'Source'
),
findsOneWidget
);
expect
(
find
.
text
(
'Dragging'
),
findsOneWidget
);
expect
(
onDragStartedCalled
,
isTrue
);
});
testWidgets
(
'Default long press delay for LongPressDraggable'
,
(
WidgetTester
tester
)
async
{
bool
onDragStartedCalled
=
false
;
await
tester
.
pumpWidget
(
MaterialApp
(
home:
LongPressDraggable
<
int
>(
data:
1
,
child:
const
Text
(
'Source'
),
feedback:
const
Text
(
'Dragging'
),
onDragStarted:
()
{
onDragStartedCalled
=
true
;
},
),
));
expect
(
find
.
text
(
'Source'
),
findsOneWidget
);
expect
(
find
.
text
(
'Dragging'
),
findsNothing
);
expect
(
onDragStartedCalled
,
isFalse
);
final
Offset
firstLocation
=
tester
.
getCenter
(
find
.
text
(
'Source'
));
await
tester
.
startGesture
(
firstLocation
,
pointer:
7
);
await
tester
.
pump
();
expect
(
find
.
text
(
'Source'
),
findsOneWidget
);
expect
(
find
.
text
(
'Dragging'
),
findsNothing
);
expect
(
onDragStartedCalled
,
isFalse
);
// Halfway into the long press duration.
await
tester
.
pump
(
const
Duration
(
milliseconds:
250
));
expect
(
find
.
text
(
'Source'
),
findsOneWidget
);
expect
(
find
.
text
(
'Dragging'
),
findsNothing
);
expect
(
onDragStartedCalled
,
isFalse
);
// Long press draggable should be showing.
await
tester
.
pump
(
const
Duration
(
milliseconds:
250
));
expect
(
find
.
text
(
'Source'
),
findsOneWidget
);
expect
(
find
.
text
(
'Dragging'
),
findsOneWidget
);
expect
(
onDragStartedCalled
,
isTrue
);
});
testWidgets
(
'long-press draggable calls Haptic Feedback onStart'
,
(
WidgetTester
tester
)
async
{
await
_testLongPressDraggableHapticFeedback
(
tester:
tester
,
hapticFeedbackOnStart:
true
,
expectedHapticFeedbackCount:
1
);
});
...
...
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