Skip to content

Commit 5e774ec

Browse files
committed
sticky_header [nfc]: Split header-overflows-sliver condition explicitly
This makes for fewer situations to think about at a given point in the code, and will make the logic a bit easier to follow when we make some corrections to the overflow case.
1 parent 2b75ad8 commit 5e774ec

File tree

1 file changed

+31
-19
lines changed

1 file changed

+31
-19
lines changed

lib/widgets/sticky_header.dart

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -617,26 +617,38 @@ class _RenderSliverStickyHeaderList extends RenderSliver with RenderSliverHelper
617617
// even if the (visible part of the) item is smaller than the header,
618618
// and even if the whole child sliver is smaller than the header.
619619

620-
final paintedHeaderSize = calculatePaintOffset(constraints, from: 0, to: headerExtent);
621-
geometry = SliverGeometry( // TODO review interaction with other slivers
622-
scrollExtent: geometry.scrollExtent,
623-
layoutExtent: childExtent,
624-
paintExtent: math.max(childExtent, paintedHeaderSize),
625-
maxPaintExtent: math.max(geometry.maxPaintExtent, headerExtent),
626-
hasVisualOverflow: geometry.hasVisualOverflow
627-
|| headerExtent > constraints.remainingPaintExtent,
628-
629-
// The cache extent is an extension of layout, not paint; it controls
630-
// where the next sliver should start laying out content. (See
631-
// [SliverConstraints.remainingCacheExtent].) The header isn't meant
632-
// to affect where the next sliver gets laid out, so it shouldn't
633-
// affect the cache extent.
634-
cacheExtent: geometry.cacheExtent,
635-
);
620+
if (headerExtent <= childExtent) {
621+
// The header fits within the child sliver.
622+
// So it doesn't affect this sliver's overall geometry.
636623

637-
headerOffset = _headerAtCoordinateEnd()
638-
? childExtent - headerExtent
639-
: 0.0;
624+
headerOffset = _headerAtCoordinateEnd()
625+
? childExtent - headerExtent
626+
: 0.0;
627+
} else {
628+
// The header will overflow the child sliver.
629+
// That makes this sliver's geometry a bit more complicated.
630+
631+
final paintedHeaderSize = calculatePaintOffset(constraints, from: 0, to: headerExtent);
632+
geometry = SliverGeometry( // TODO review interaction with other slivers
633+
scrollExtent: geometry.scrollExtent,
634+
layoutExtent: childExtent,
635+
paintExtent: math.max(childExtent, paintedHeaderSize),
636+
maxPaintExtent: math.max(geometry.maxPaintExtent, headerExtent),
637+
hasVisualOverflow: geometry.hasVisualOverflow
638+
|| headerExtent > constraints.remainingPaintExtent,
639+
640+
// The cache extent is an extension of layout, not paint; it controls
641+
// where the next sliver should start laying out content. (See
642+
// [SliverConstraints.remainingCacheExtent].) The header isn't meant
643+
// to affect where the next sliver gets laid out, so it shouldn't
644+
// affect the cache extent.
645+
cacheExtent: geometry.cacheExtent,
646+
);
647+
648+
headerOffset = _headerAtCoordinateEnd()
649+
? childExtent - headerExtent
650+
: 0.0;
651+
}
640652
} else {
641653
// The header's item has [StickyHeaderItem.allowOverflow] false.
642654
// Keep the header within the item, pushing the header partly out of

0 commit comments

Comments
 (0)