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

Add doc and test for Container's hitTest behavior #57522

Merged
merged 2 commits into from Jun 2, 2020

Conversation

dkwingsmt
Copy link
Contributor

@dkwingsmt dkwingsmt commented May 18, 2020

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:

  • Container is hittable if and only if it has color or any decorations

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.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read Handling breaking changes.

  • No, no existing tests failed, so this is not a breaking change.

@fluttergithubbot fluttergithubbot added the framework flutter/packages/flutter repository. See also f: labels. label May 18, 2020
Comment on lines 187 to 189
/// 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].
Copy link
Contributor

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.

Copy link
Contributor Author

@dkwingsmt dkwingsmt May 19, 2020

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';
Copy link
Contributor

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.

Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

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

LGTM

@goderbauer
Copy link
Member

(PR triage): @dkwingsmt is this one ready to go?

@fluttergithubbot fluttergithubbot merged commit 729ba11 into flutter:master Jun 2, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 31, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants