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
7b07b85d
Unverified
Commit
7b07b85d
authored
Jul 21, 2022
by
Callum Moffat
Committed by
GitHub
Jul 21, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add supportedDevices parameter to GestureDetector (#107312)
parent
22f51c34
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
8 deletions
+61
-8
gesture_detector.dart
packages/flutter/lib/src/widgets/gesture_detector.dart
+14
-8
gesture_detector_test.dart
packages/flutter/test/widgets/gesture_detector_test.dart
+47
-0
No files found.
packages/flutter/lib/src/widgets/gesture_detector.dart
View file @
7b07b85d
...
...
@@ -288,6 +288,7 @@ class GestureDetector extends StatelessWidget {
this
.
behavior
,
this
.
excludeFromSemantics
=
false
,
this
.
dragStartBehavior
=
DragStartBehavior
.
start
,
this
.
supportedDevices
,
})
:
assert
(
excludeFromSemantics
!=
null
),
assert
(
dragStartBehavior
!=
null
),
assert
(()
{
...
...
@@ -1004,6 +1005,11 @@ class GestureDetector extends StatelessWidget {
/// * [DragGestureRecognizer.dragStartBehavior], which gives an example for the different behaviors.
final
DragStartBehavior
dragStartBehavior
;
/// The kind of devices that are allowed to be recognized.
///
/// If set to null, events from all device types will be recognized. Defaults to null.
final
Set
<
PointerDeviceKind
>?
supportedDevices
;
@override
Widget
build
(
BuildContext
context
)
{
final
Map
<
Type
,
GestureRecognizerFactory
>
gestures
=
<
Type
,
GestureRecognizerFactory
>{};
...
...
@@ -1022,7 +1028,7 @@ class GestureDetector extends StatelessWidget {
onTertiaryTapCancel
!=
null
)
{
gestures
[
TapGestureRecognizer
]
=
GestureRecognizerFactoryWithHandlers
<
TapGestureRecognizer
>(
()
=>
TapGestureRecognizer
(
debugOwner:
this
),
()
=>
TapGestureRecognizer
(
debugOwner:
this
,
supportedDevices:
supportedDevices
),
(
TapGestureRecognizer
instance
)
{
instance
..
onTapDown
=
onTapDown
...
...
@@ -1043,7 +1049,7 @@ class GestureDetector extends StatelessWidget {
if
(
onDoubleTap
!=
null
)
{
gestures
[
DoubleTapGestureRecognizer
]
=
GestureRecognizerFactoryWithHandlers
<
DoubleTapGestureRecognizer
>(
()
=>
DoubleTapGestureRecognizer
(
debugOwner:
this
),
()
=>
DoubleTapGestureRecognizer
(
debugOwner:
this
,
supportedDevices:
supportedDevices
),
(
DoubleTapGestureRecognizer
instance
)
{
instance
..
onDoubleTapDown
=
onDoubleTapDown
...
...
@@ -1076,7 +1082,7 @@ class GestureDetector extends StatelessWidget {
onTertiaryLongPressUp
!=
null
||
onTertiaryLongPressEnd
!=
null
)
{
gestures
[
LongPressGestureRecognizer
]
=
GestureRecognizerFactoryWithHandlers
<
LongPressGestureRecognizer
>(
()
=>
LongPressGestureRecognizer
(
debugOwner:
this
),
()
=>
LongPressGestureRecognizer
(
debugOwner:
this
,
supportedDevices:
supportedDevices
),
(
LongPressGestureRecognizer
instance
)
{
instance
..
onLongPressDown
=
onLongPressDown
...
...
@@ -1111,7 +1117,7 @@ class GestureDetector extends StatelessWidget {
onVerticalDragEnd
!=
null
||
onVerticalDragCancel
!=
null
)
{
gestures
[
VerticalDragGestureRecognizer
]
=
GestureRecognizerFactoryWithHandlers
<
VerticalDragGestureRecognizer
>(
()
=>
VerticalDragGestureRecognizer
(
debugOwner:
this
),
()
=>
VerticalDragGestureRecognizer
(
debugOwner:
this
,
supportedDevices:
supportedDevices
),
(
VerticalDragGestureRecognizer
instance
)
{
instance
..
onDown
=
onVerticalDragDown
...
...
@@ -1131,7 +1137,7 @@ class GestureDetector extends StatelessWidget {
onHorizontalDragEnd
!=
null
||
onHorizontalDragCancel
!=
null
)
{
gestures
[
HorizontalDragGestureRecognizer
]
=
GestureRecognizerFactoryWithHandlers
<
HorizontalDragGestureRecognizer
>(
()
=>
HorizontalDragGestureRecognizer
(
debugOwner:
this
),
()
=>
HorizontalDragGestureRecognizer
(
debugOwner:
this
,
supportedDevices:
supportedDevices
),
(
HorizontalDragGestureRecognizer
instance
)
{
instance
..
onDown
=
onHorizontalDragDown
...
...
@@ -1151,7 +1157,7 @@ class GestureDetector extends StatelessWidget {
onPanEnd
!=
null
||
onPanCancel
!=
null
)
{
gestures
[
PanGestureRecognizer
]
=
GestureRecognizerFactoryWithHandlers
<
PanGestureRecognizer
>(
()
=>
PanGestureRecognizer
(
debugOwner:
this
),
()
=>
PanGestureRecognizer
(
debugOwner:
this
,
supportedDevices:
supportedDevices
),
(
PanGestureRecognizer
instance
)
{
instance
..
onDown
=
onPanDown
...
...
@@ -1167,7 +1173,7 @@ class GestureDetector extends StatelessWidget {
if
(
onScaleStart
!=
null
||
onScaleUpdate
!=
null
||
onScaleEnd
!=
null
)
{
gestures
[
ScaleGestureRecognizer
]
=
GestureRecognizerFactoryWithHandlers
<
ScaleGestureRecognizer
>(
()
=>
ScaleGestureRecognizer
(
debugOwner:
this
),
()
=>
ScaleGestureRecognizer
(
debugOwner:
this
,
supportedDevices:
supportedDevices
),
(
ScaleGestureRecognizer
instance
)
{
instance
..
onStart
=
onScaleStart
...
...
@@ -1184,7 +1190,7 @@ class GestureDetector extends StatelessWidget {
onForcePressUpdate
!=
null
||
onForcePressEnd
!=
null
)
{
gestures
[
ForcePressGestureRecognizer
]
=
GestureRecognizerFactoryWithHandlers
<
ForcePressGestureRecognizer
>(
()
=>
ForcePressGestureRecognizer
(
debugOwner:
this
),
()
=>
ForcePressGestureRecognizer
(
debugOwner:
this
,
supportedDevices:
supportedDevices
),
(
ForcePressGestureRecognizer
instance
)
{
instance
..
onStart
=
onForcePressStart
...
...
packages/flutter/test/widgets/gesture_detector_test.dart
View file @
7b07b85d
...
...
@@ -875,6 +875,53 @@ void main() {
});
});
});
testWidgets
(
'supportedDevices is respected'
,
(
WidgetTester
tester
)
async
{
bool
didStartPan
=
false
;
Offset
?
panDelta
;
bool
didEndPan
=
false
;
await
tester
.
pumpWidget
(
GestureDetector
(
onPanStart:
(
DragStartDetails
details
)
{
didStartPan
=
true
;
},
onPanUpdate:
(
DragUpdateDetails
details
)
{
panDelta
=
(
panDelta
??
Offset
.
zero
)
+
details
.
delta
;
},
onPanEnd:
(
DragEndDetails
details
)
{
didEndPan
=
true
;
},
supportedDevices:
const
<
PointerDeviceKind
>{
PointerDeviceKind
.
mouse
},
child:
Container
(
color:
const
Color
(
0xFF00FF00
),
)
),
);
expect
(
didStartPan
,
isFalse
);
expect
(
panDelta
,
isNull
);
expect
(
didEndPan
,
isFalse
);
await
tester
.
dragFrom
(
const
Offset
(
10.0
,
10.0
),
const
Offset
(
20.0
,
30.0
),
kind:
PointerDeviceKind
.
mouse
);
// Matching device should allow gesture.
expect
(
didStartPan
,
isTrue
);
expect
(
panDelta
!.
dx
,
20.0
);
expect
(
panDelta
!.
dy
,
30.0
);
expect
(
didEndPan
,
isTrue
);
didStartPan
=
false
;
panDelta
=
null
;
didEndPan
=
false
;
await
tester
.
dragFrom
(
const
Offset
(
10.0
,
10.0
),
const
Offset
(
20.0
,
30.0
),
kind:
PointerDeviceKind
.
stylus
);
// Non-matching device should not lead to any callbacks.
expect
(
didStartPan
,
isFalse
);
expect
(
panDelta
,
isNull
);
expect
(
didEndPan
,
isFalse
);
});
}
class
_EmptySemanticsGestureDelegate
extends
SemanticsGestureDelegate
{
...
...
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