Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect when tap target is covered #61

Merged
merged 27 commits into from
Jun 27, 2024
Merged

Detect when tap target is covered #61

merged 27 commits into from
Jun 27, 2024

Conversation

passsy
Copy link
Owner

@passsy passsy commented Jun 27, 2024

await act.tap(button); just got way more helpful in two cases:

tap target covered by another widget

Shows a useful diagram when a widget can't be tapped because it is covered by another widget consuming the tap events.

Selector 'Widget with text contains text "Press Me"' can not be tapped directly, because another
widget (Listener) inside Padding is completely covering it and consumes all tap events.

Try tapping the Padding which contains 'Widget with text contains text "Press Me"' instead.

Example:
  // BAD: Taps the Text inside ElevatedButton
  WidgetSelector<AnyText> selector = spot<ElevatedButton>().spotText('Tap me');
  await act.tap(selector);

  // GOOD: Taps the ElevatedButton which contains text 'Tap me'
  WidgetSelector<ElevatedButton> selector = spot<ElevatedButton>().withChild(spotText('Tap me'));
  await act.tap(selector);

(Cover - Received tap event)             (Target for tap, below Cover)
Listener                                 RichText
RawGestureDetector                       Text
GestureDetector                           │
Semantics                                 │
DefaultSelectionStyle                     │
Builder                                   │
MouseRegion                               │
Semantics                                 │
_FocusInheritedScope                      │
Focus                                     │
_ActionsScope                             │
Actions                                   │
_ParentInkResponseProvider                │
_InkResponseStateWidget                   │
InkWell                                   │
DefaultTextStyle                          │
AnimatedDefaultTextStyle                  │
_InkFeatures-[GlobalKey#7028f ink render  │
NotificationListener<LayoutChangedNotifi  │
PhysicalModel                             │
AnimatedPhysicalModel                     │
Material                                  │
Positioned                                │
 │ ┌──────────────────────────────────────┘
Stack (file:///Users/pascalwelsch/Projects/passsy/spot/test/act/find_tappable_area_test.dart:242:14)
Padding
(file:///Users/pascalwelsch/Projects/passsy/spot/test/act/find_tappable_area_test.dart:240:12)

When the exception was thrown, this was the stack:
#0      Act._detectCoverWidget (package:spot/src/act/act.dart:590:5)
#1      Act._throwHitTestFailureReport (package:spot/src/act/act.dart:310:5)
#2      Act.tap.<anonymous closure>.<anonymous closure> (package:spot/src/act/act.dart:97:11)
#3      _alwaysPropagateDevicePointerEvents (package:spot/src/act/act.dart:670:17)
#4      Act.tap.<anonymous closure> (package:spot/src/act/act.dart:83:14)
#7      TestAsyncUtils.guard (package:flutter_test/src/test_async_utils.dart:71:41)
#8      Act.tap (package:spot/src/act/act.dart:82:27)
#9      main.<anonymous closure> (file:///Users/pascalwelsch/Projects/passsy/spot/test/act/find_tappable_area_test.dart:181:15)
<asynchronous suspension>
#10     testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart:183:15)
<asynchronous suspension>
#11     TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:1017:5)
<asynchronous suspension>
<asynchronous suspension>
(elided 3 frames from dart:async and package:stack_trace)

tap target is 0x0 pixels

Also shows a useful error when the size of a widget is 0x0

ElevatedButton can't be tapped because it has size Size(0.0, 0.0).
SizedBox.shrink forces ElevatedButton to have the size Size(0.0, 0.0).
SizedBox.shrink file:///Users/pascalwelsch/Projects/passsy/spot/test/act/act_test.dart:335:29

When the exception was thrown, this was the stack:
#0      Act._detectSizeZero (package:spot/src/act/act.dart:503:7)
#1      Act._throwHitTestFailureReport (package:spot/src/act/act.dart:309:5)
#2      Act.tap.<anonymous closure>.<anonymous closure> (package:spot/src/act/act.dart:97:11)
#3      _alwaysPropagateDevicePointerEvents (package:spot/src/act/act.dart:670:17)
#4      Act.tap.<anonymous closure> (package:spot/src/act/act.dart:83:14)
#7      TestAsyncUtils.guard (package:flutter_test/src/test_async_utils.dart:71:41)
#8      Act.tap (package:spot/src/act/act.dart:82:27)
#9      actTests.<anonymous closure>.<anonymous closure> (file:///Users/pascalwelsch/Projects/passsy/spot/test/act/act_test.dart:349:17)

danielmolnar and others added 26 commits June 21, 2024 17:41
Implement a dual-phase search strategy in _findPokablePosition to first
test high-probability interaction points and then perform a comprehensive
zigzag grid search. This approach balances speed with thorough coverage
of the widget area. Also update the function's documentation to clearly
explain the new strategy and its benefits.
…button

# Conflicts:
#	lib/src/act/act.dart
#	test/act/find_tappable_area_test.dart
Copy link
Collaborator

@danielmolnar danielmolnar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NdG

@passsy passsy merged commit 5d9faf1 into main Jun 27, 2024
4 checks passed
@passsy passsy deleted the tap-text-in-elevated-button branch June 27, 2024 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants