-
Notifications
You must be signed in to change notification settings - Fork 30.6k
[InkWell] fix: Prevent disabled buttons from passing taps to parent GestureDetectors #187551
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
base: master
Are you sure you want to change the base?
Changes from all commits
77fd24f
f80d5b9
c742fe7
41b2013
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -571,6 +571,16 @@ class _ButtonStyleState extends State<ButtonStyleButton> with TickerProviderStat | |
| ), | ||
| ); | ||
|
|
||
| // When the button is disabled, absorb taps to prevent them from | ||
| // propagating to parent gesture detectors. | ||
| // See https://github.com/flutter/flutter/issues/138981 | ||
| result = GestureDetector( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not wrap with an
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is what I thought as well... I wrote it in the PR description: Approaches ConsideredAbsorbPointer: Tried wrapping the InkWell with AbsorbPointer(absorbing: !widget.enabled), but this doesn't work. AbsorbPointer.hitTest returns true without adding itself to the hit test result, which still causes the parent GestureDetector to add itself via hitTestChildren and fire its callback. |
||
| onTap: widget.enabled ? null : () {}, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need to worry about ancestor |
||
| behavior: widget.enabled ? HitTestBehavior.deferToChild : HitTestBehavior.opaque, | ||
| excludeFromSemantics: true, | ||
| child: result, | ||
| ); | ||
|
Comment on lines
+577
to
+582
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When the button is enabled, Using result = GestureDetector(
onTap: widget.enabled ? null : () {},
behavior: widget.enabled ? HitTestBehavior.deferToChild : HitTestBehavior.opaque,
excludeFromSemantics: true,
child: result,
);
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed it to |
||
|
|
||
| if (widget.tooltip != null) { | ||
| result = Tooltip(message: widget.tooltip, child: result); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: this is not pointer absorption, this is gesture arena competition. So technically we are not absorbing taps (the way
AbsorbPointerdoes), we are claiming taps so that ancestor tap recognizers do not win.