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
7122a009
Unverified
Commit
7122a009
authored
Aug 30, 2022
by
Greg Spencer
Committed by
GitHub
Aug 30, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix some tap region bugs (#110398)
parent
ee98003e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
136 additions
and
30 deletions
+136
-30
tap_region.dart
packages/flutter/lib/src/widgets/tap_region.dart
+8
-2
tap_region_test.dart
packages/flutter/test/widgets/tap_region_test.dart
+128
-28
No files found.
packages/flutter/lib/src/widgets/tap_region.dart
View file @
7122a009
...
...
@@ -406,7 +406,7 @@ class TapRegion extends SingleChildRenderObjectWidget {
///
/// * [TapRegion], a widget that inserts a [RenderTapRegion] into the render
/// tree.
class
RenderTapRegion
extends
RenderProxyBox
with
Diagnosticable
{
class
RenderTapRegion
extends
RenderProxyBox
{
/// Creates a [RenderTapRegion].
RenderTapRegion
({
TapRegionRegistry
?
registry
,
...
...
@@ -464,6 +464,12 @@ class RenderTapRegion extends RenderProxyBox with Diagnosticable {
Object
?
_groupId
;
set
groupId
(
Object
?
value
)
{
if
(
_groupId
!=
value
)
{
// If the group changes, we need to unregister and re-register under the
// new group. The re-registration happens automatically in layout().
if
(
_isRegistered
)
{
_registry
!.
unregisterTapRegion
(
this
);
_isRegistered
=
false
;
}
_groupId
=
value
;
markNeedsLayout
();
}
...
...
@@ -515,7 +521,7 @@ class RenderTapRegion extends RenderProxyBox with Diagnosticable {
@override
void
debugFillProperties
(
DiagnosticPropertiesBuilder
properties
)
{
super
.
debugFillProperties
(
properties
);
properties
.
add
(
DiagnosticsProperty
<
Object
?>(
'debugLabel'
,
debugLabel
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
String
?>(
'debugLabel'
,
debugLabel
,
defaultValue:
null
));
properties
.
add
(
DiagnosticsProperty
<
Object
?>(
'groupId'
,
groupId
,
defaultValue:
null
));
properties
.
add
(
FlagProperty
(
'enabled'
,
value:
enabled
,
ifFalse:
'DISABLED'
,
defaultValue:
true
));
}
...
...
packages/flutter/test/widgets/tap_region_test.dart
View file @
7122a009
...
...
@@ -9,7 +9,7 @@ import 'package:flutter_test/flutter_test.dart';
void
main
(
)
{
testWidgets
(
'TapRegionSurface detects outside taps'
,
(
WidgetTester
tester
)
async
{
final
Set
<
String
>
click
edOutside
=
<
String
>{};
final
Set
<
String
>
tapp
edOutside
=
<
String
>{};
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
...
...
@@ -22,21 +22,21 @@ void main() {
const
Text
(
'Outside'
),
TapRegion
(
onTapOutside:
(
PointerEvent
event
)
{
click
edOutside
.
add
(
'No Group'
);
tapp
edOutside
.
add
(
'No Group'
);
},
child:
const
Text
(
'No Group'
),
),
TapRegion
(
groupId:
1
,
onTapOutside:
(
PointerEvent
event
)
{
click
edOutside
.
add
(
'Group 1 A'
);
tapp
edOutside
.
add
(
'Group 1 A'
);
},
child:
const
Text
(
'Group 1 A'
),
),
TapRegion
(
groupId:
1
,
onTapOutside:
(
PointerEvent
event
)
{
click
edOutside
.
add
(
'Group 1 B'
);
tapp
edOutside
.
add
(
'Group 1 B'
);
},
child:
const
Text
(
'Group 1 B'
),
),
...
...
@@ -59,48 +59,48 @@ void main() {
await
gesture
.
removePointer
();
}
expect
(
click
edOutside
,
isEmpty
);
expect
(
tapp
edOutside
,
isEmpty
);
await
click
(
find
.
text
(
'No Group'
));
expect
(
click
edOutside
,
tapp
edOutside
,
unorderedEquals
(<
String
>{
'Group 1 A'
,
'Group 1 B'
,
}));
click
edOutside
.
clear
();
tapp
edOutside
.
clear
();
await
click
(
find
.
text
(
'Group 1 A'
));
expect
(
click
edOutside
,
tapp
edOutside
,
equals
(<
String
>{
'No Group'
,
}));
click
edOutside
.
clear
();
tapp
edOutside
.
clear
();
await
click
(
find
.
text
(
'Group 1 B'
));
expect
(
click
edOutside
,
tapp
edOutside
,
equals
(<
String
>{
'No Group'
,
}));
click
edOutside
.
clear
();
tapp
edOutside
.
clear
();
await
click
(
find
.
text
(
'Outside'
));
expect
(
click
edOutside
,
tapp
edOutside
,
unorderedEquals
(<
String
>{
'No Group'
,
'Group 1 A'
,
'Group 1 B'
,
}));
click
edOutside
.
clear
();
tapp
edOutside
.
clear
();
await
click
(
find
.
text
(
'Outside Surface'
));
expect
(
click
edOutside
,
isEmpty
);
expect
(
tapp
edOutside
,
isEmpty
);
});
testWidgets
(
'TapRegionSurface detects inside taps'
,
(
WidgetTester
tester
)
async
{
final
Set
<
String
>
click
edInside
=
<
String
>{};
final
Set
<
String
>
tapp
edInside
=
<
String
>{};
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
...
...
@@ -113,21 +113,21 @@ void main() {
const
Text
(
'Outside'
),
TapRegion
(
onTapInside:
(
PointerEvent
event
)
{
click
edInside
.
add
(
'No Group'
);
tapp
edInside
.
add
(
'No Group'
);
},
child:
const
Text
(
'No Group'
),
),
TapRegion
(
groupId:
1
,
onTapInside:
(
PointerEvent
event
)
{
click
edInside
.
add
(
'Group 1 A'
);
tapp
edInside
.
add
(
'Group 1 A'
);
},
child:
const
Text
(
'Group 1 A'
),
),
TapRegion
(
groupId:
1
,
onTapInside:
(
PointerEvent
event
)
{
click
edInside
.
add
(
'Group 1 B'
);
tapp
edInside
.
add
(
'Group 1 B'
);
},
child:
const
Text
(
'Group 1 B'
),
),
...
...
@@ -150,39 +150,139 @@ void main() {
await
gesture
.
removePointer
();
}
expect
(
click
edInside
,
isEmpty
);
expect
(
tapp
edInside
,
isEmpty
);
await
click
(
find
.
text
(
'No Group'
));
expect
(
click
edInside
,
tapp
edInside
,
unorderedEquals
(<
String
>{
'No Group'
,
}));
click
edInside
.
clear
();
tapp
edInside
.
clear
();
await
click
(
find
.
text
(
'Group 1 A'
));
expect
(
click
edInside
,
tapp
edInside
,
equals
(<
String
>{
'Group 1 A'
,
'Group 1 B'
,
}));
click
edInside
.
clear
();
tapp
edInside
.
clear
();
await
click
(
find
.
text
(
'Group 1 B'
));
expect
(
click
edInside
,
tapp
edInside
,
equals
(<
String
>{
'Group 1 A'
,
'Group 1 B'
,
}));
click
edInside
.
clear
();
tapp
edInside
.
clear
();
await
click
(
find
.
text
(
'Outside'
));
expect
(
click
edInside
,
isEmpty
);
click
edInside
.
clear
();
expect
(
tapp
edInside
,
isEmpty
);
tapp
edInside
.
clear
();
await
click
(
find
.
text
(
'Outside Surface'
));
expect
(
clickedInside
,
isEmpty
);
expect
(
tappedInside
,
isEmpty
);
});
testWidgets
(
'Setting the group updates the registration'
,
(
WidgetTester
tester
)
async
{
final
Set
<
String
>
tappedOutside
=
<
String
>{};
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
TapRegionSurface
(
child:
Row
(
children:
<
Widget
>[
const
Text
(
'Outside'
),
TapRegion
(
groupId:
1
,
onTapOutside:
(
PointerEvent
event
)
{
tappedOutside
.
add
(
'Group 1 A'
);
},
child:
const
Text
(
'Group 1 A'
),
),
TapRegion
(
groupId:
1
,
onTapOutside:
(
PointerEvent
event
)
{
tappedOutside
.
add
(
'Group 1 B'
);
},
child:
const
Text
(
'Group 1 B'
),
),
],
),
),
),
);
await
tester
.
pump
();
Future
<
void
>
click
(
Finder
finder
)
async
{
final
TestGesture
gesture
=
await
tester
.
startGesture
(
tester
.
getCenter
(
finder
),
kind:
PointerDeviceKind
.
mouse
,
);
await
gesture
.
up
();
await
gesture
.
removePointer
();
}
expect
(
tappedOutside
,
isEmpty
);
await
click
(
find
.
text
(
'Group 1 A'
));
expect
(
tappedOutside
,
isEmpty
);
await
click
(
find
.
text
(
'Group 1 B'
));
expect
(
tappedOutside
,
isEmpty
);
await
click
(
find
.
text
(
'Outside'
));
expect
(
tappedOutside
,
equals
(<
String
>[
'Group 1 A'
,
'Group 1 B'
,
]));
tappedOutside
.
clear
();
// Now change out the groups.
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
TapRegionSurface
(
child:
Row
(
children:
<
Widget
>[
const
Text
(
'Outside'
),
TapRegion
(
groupId:
1
,
onTapOutside:
(
PointerEvent
event
)
{
tappedOutside
.
add
(
'Group 1 A'
);
},
child:
const
Text
(
'Group 1 A'
),
),
TapRegion
(
groupId:
2
,
onTapOutside:
(
PointerEvent
event
)
{
tappedOutside
.
add
(
'Group 2 A'
);
},
child:
const
Text
(
'Group 2 A'
),
),
],
),
),
),
);
await
click
(
find
.
text
(
'Group 1 A'
));
expect
(
tappedOutside
,
equals
(<
String
>[
'Group 2 A'
]));
tappedOutside
.
clear
();
await
click
(
find
.
text
(
'Group 2 A'
));
expect
(
tappedOutside
,
equals
(<
String
>[
'Group 1 A'
]));
tappedOutside
.
clear
();
await
click
(
find
.
text
(
'Outside'
));
expect
(
tappedOutside
,
equals
(<
String
>[
'Group 1 A'
,
'Group 2 A'
,
]));
tappedOutside
.
clear
();
});
}
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