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
Add doc and test for Container's hitTest behavior #57522
Conversation
/// A container by itself is hittable during a hit test if and only if it has | ||
/// [color], [decoration], or [foregroundDecoration]. By using decorations, | ||
/// the hittability will be decided by [Decoration.hitTest]. |
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.
I think this is true, but it's a little bit difficult to parse. Maybe
By default, containers return false for all hit tests. If the [color] property is specified, the hit testing is handled by [ColoredBox], which always returns true. If the [decoration] or [foregroundDecoration] properties are specified, hit testing is handled by [Decoration.hitTest], which also always returns true.
It's a little unsettling to be documenting such behavior of other widgets, but I don't see how that could change without some kind of break anyway at this point.
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.
I don't think it's fair to say Decoration.hitTest
always returns true, since the subclass will very likely override it, such as in ShapeDecoration.
Other than that, I've updated the doc. Thanks for the suggestion.
@@ -2,6 +2,7 @@ | |||
// Use of this source code is governed by a BSD-style license that can be | |||
// found in the LICENSE file. | |||
|
|||
import 'package:flutter/material.dart'; |
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.
uber nit: this looks a little weird in widgets
, I guess it's so you can use Colors
? I have a vague hope that someday we could run tests based on what they import, and things like this will probably have to be rewritten. But it happens elsewhere, it's ok to leave for now.
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.
LGTM
(PR triage): @dkwingsmt is this one ready to go? |
Description
A lot of people use Container as a hit test target. This PR adds docs and tests for container's hit test behavior.
Related Issues
Tests
I added the following tests:
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]
). This will ensure a smooth and quick review process.///
).flutter analyze --flutter-repo
) does not report any problems on my PR.Breaking Change
Did any tests fail when you ran them? Please read Handling breaking changes.