Visitar URL original
Colored box and container optimization by dnfield · Pull Request #50979 · flutter/flutter · GitHub
Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
better hit test?
  • Loading branch information
dnfield committed Feb 18, 2020
commit 73e60349606fdb7d89c68352308a1596233c707d
14 changes: 9 additions & 5 deletions packages/flutter/lib/src/widgets/basic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7096,8 +7096,10 @@ class ColoredBox extends SingleChildRenderObjectWidget {
}
}

class _RenderColoredBox extends RenderProxyBox {
_RenderColoredBox({@required Color color}) : _color = color;
class _RenderColoredBox extends RenderProxyBoxWithHitTestBehavior {
_RenderColoredBox({@required Color color})
: _color = color,
super(behavior: color.alpha == 0 ? HitTestBehavior.deferToChild : HitTestBehavior.opaque);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This surprised me. Was the container doing anything special with hittest behavior based on transparency?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm going to file a new bug for this: #51000 - agree we shouldn't introduce new behavior here (and not behavior that would differ from using a decoration)


/// The fill color for this render object.
///
Expand All @@ -7110,12 +7112,14 @@ class _RenderColoredBox extends RenderProxyBox {
return;
}
_color = value;
if (color.alpha == 0) {
behavior = HitTestBehavior.deferToChild;
} else {
behavior = HitTestBehavior.opaque;
}
markNeedsPaint();
}

@override
bool hitTestSelf(Offset position) => true;

@override
void paint(PaintingContext context, Offset offset) {
if (size > Size.zero) {
Expand Down