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

Make InkDecoration not paint if the ink is not visible #122585

Merged
merged 1 commit into from Mar 25, 2023

Conversation

tvolkert
Copy link
Contributor

@tvolkert tvolkert commented Mar 14, 2023

Make InkDecoraiton not paint if the ink is not visible

This introduces a isVisible field in InkDecoration to control whether
the decoration is painted. It also introduces a Visibility.of() method
that can be used to determine the visibility state of widgets in the tree
based on Visibility ancestry state. This then updates Ink to consult
Visibility.of() and set the visible flag on its ink decoration
accordingly.

Finally, this updates IndexedStack to add a Visibility widget around
each of the stack's children, so that non-visible children of the stack
will be able to use Visibility.of() to know their visibility.

Putting it all together, this means that ink no longer paints itself when
it's in a non-selected index of an indexed stack.

#59963

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • All existing and new tests are passing.

@flutter-dashboard flutter-dashboard bot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Mar 14, 2023
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@tvolkert
Copy link
Contributor Author

@goderbauer or @HansMuller before I work hard on polish, I'm interested in if you think this is a decent way to go about this.

@override
Widget build(BuildContext context) {
List<Widget> wrappedChildren = List<Widget>.generate(children.length, (int i) {
return Visibility(
Copy link
Member

Choose a reason for hiding this comment

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

To maintain the documented properties of the IndexedStack ("The stack is always as big as the largest child.") this must set maintainSize to true.

Copy link
Member

Choose a reason for hiding this comment

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

(I hope we have a test that's failing because of this, if not, could you please add one?)

@@ -224,39 +224,46 @@ class Visibility extends StatelessWidget {
/// objects, to be immediately created if [visible] is true).
final bool maintainInteractivity;

static VisibilityMarker of(BuildContext context) {
Copy link
Member

Choose a reason for hiding this comment

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

Wondering: Should this just return true/false? Do you have any plans to extend VisibilityMarker? Or ideas what we should add in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point - returning a boolean is cleaner.

@goderbauer
Copy link
Member

To fully evaluate this, it would be useful to see what it would take to get all tests to pass again. Are those just failing because of the maintainSize problem? Or is there more to it?

@tvolkert
Copy link
Contributor Author

Thanks @goderbauer! The failing tests were just due to the need to use Visibility.maintain(). I'm gonna clean this up a bit and will let you know when it's ready for a real review.

@tvolkert tvolkert changed the title [WIP] Make InkDecoration not paint if the ink is not visible Make InkDecoration not paint if the ink is not visible Mar 14, 2023
@tvolkert
Copy link
Contributor Author

Ok, @goderbauer I think this is ready for a real review.

@@ -279,13 +279,15 @@ class _InkState extends State<Ink> {
if (_ink == null) {
_ink = InkDecoration(
decoration: widget.decoration,
isVisible: Visibility.of(context),
Copy link
Member

Choose a reason for hiding this comment

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

Can it be extended to parameters like boundaries to solve these issues at the same time?

@tvolkert
Copy link
Contributor Author

ping @goderbauer 🙂

Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines 366 to 367
bool get isVisible => _isVisible ?? true;
bool? _isVisible;
Copy link
Member

Choose a reason for hiding this comment

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

It looks like the fact that _isVisible is nullable is not really important? Maybe simplify to

Suggested change
bool get isVisible => _isVisible ?? true;
bool? _isVisible;
bool get isVisible => _isVisible;
bool _isVisible = true;

@tvolkert tvolkert added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 22, 2023
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Mar 22, 2023
@auto-submit
Copy link
Contributor

auto-submit bot commented Mar 22, 2023

auto label is removed for flutter/flutter, pr: 122585, due to - The status or check suite Linux firebase_abstract_method_smoke_test has failed. Please fix the issues identified (or deflake) before re-applying this label.

This introduces a `isVisible` field in `InkDecoration` to control whether
the decoration is painted. It also introduces a `Visibility.of()` method
that can be used to determine the visibility state of widgets in the tree
based on Visibility ancestry state. This then updates Ink to consult
`Visibility.of()` and set the visible flag on its ink decoration
accordingly.

Finally, this updates `IndexedStack` to add a `Visibility` widget around
each of the stack's children, so that non-visible children of the stack
will be able to use `Visibility.of()` to know their visibility.

Putting it all together, this means that ink no longer paints itself when
it's in a non-selected index of an indexed stack.

flutter#59963
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants