Skip to content

Commit 2b75ad8

Browse files
committed
sticky_header [nfc]: Fix childMainAxisPosition to properly use paintExtent
This fixes a latent bug: this method would give wrong answers if the sliver's paintExtent differed from its layoutExtent. The bug is latent because performLayout currently always produces a layoutExtent equal to paintExtent. But we'll start making them differ soon, as part of making hit-testing work correctly when a sticky header is painted by one sliver but needs to encroach on the layout area of another sliver. The framework calls this method as part of hit-testing, so that requires fixing this bug too.
1 parent 1907fba commit 2b75ad8

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

lib/widgets/sticky_header.dart

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -691,16 +691,21 @@ class _RenderSliverStickyHeaderList extends RenderSliver with RenderSliverHelper
691691
double childMainAxisPosition(RenderObject child) {
692692
if (child == this.child) return 0.0;
693693
assert(child == header);
694+
695+
final headerParentData = (header!.parentData as SliverPhysicalParentData);
696+
final paintOffset = headerParentData.paintOffset;
697+
694698
// We use Sliver*Physical*ParentData, so the header's position is stored in
695699
// physical coordinates. To meet the spec of `childMainAxisPosition`, we
696700
// need to convert to the sliver's coordinate system.
697-
final headerParentData = (header!.parentData as SliverPhysicalParentData);
698-
final paintOffset = headerParentData.paintOffset;
701+
// This is all a bit silly because callers like [hitTestBoxChild] are just
702+
// going to do the same things in reverse to get physical coordinates.
703+
// Ah well; that's the API.
699704
return switch (constraints.growthAxisDirection) {
700705
AxisDirection.right => paintOffset.dx,
701-
AxisDirection.left => geometry!.layoutExtent - header!.size.width - paintOffset.dx,
706+
AxisDirection.left => geometry!.paintExtent - header!.size.width - paintOffset.dx,
702707
AxisDirection.down => paintOffset.dy,
703-
AxisDirection.up => geometry!.layoutExtent - header!.size.height - paintOffset.dy,
708+
AxisDirection.up => geometry!.paintExtent - header!.size.height - paintOffset.dy,
704709
};
705710
}
706711

0 commit comments

Comments
 (0)