From 97b7700daee8deb6aa8320c32966108f7613b03c Mon Sep 17 00:00:00 2001 From: pathconnected Date: Wed, 26 Feb 2025 01:59:52 +0100 Subject: [PATCH] Set SliverResizingHeader's maxScrollObstructionExtent to minExtent (#162955) The maxScrollObstructionExtent of a Sliver denotes the "maximum extent by which this sliver can reduce the area in which content can scroll if the sliver were pinned at the edge.". See also the rest of the documentation of this field. In the case of SliverResizingHeader, like with SliverPersistentHeader, we expect this value to be minExtent. A use case is provided in the referenced issue. Fixes #162661. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --------- Co-authored-by: Victor Sanni --- .../src/widgets/sliver_resizing_header.dart | 2 +- .../widgets/sliver_resizing_header_test.dart | 53 +++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/widgets/sliver_resizing_header.dart b/packages/flutter/lib/src/widgets/sliver_resizing_header.dart index 1a5041e4cf..69e7c2a48d 100644 --- a/packages/flutter/lib/src/widgets/sliver_resizing_header.dart +++ b/packages/flutter/lib/src/widgets/sliver_resizing_header.dart @@ -223,7 +223,7 @@ class _RenderSliverResizingHeader extends RenderSliver paintExtent: math.min(childExtent, remainingPaintExtent), layoutExtent: clampDouble(layoutExtent, 0, remainingPaintExtent), maxPaintExtent: childExtent, - maxScrollObstructionExtent: childExtent, + maxScrollObstructionExtent: minExtent, cacheExtent: calculateCacheOffset(constraints, from: 0.0, to: childExtent), hasVisualOverflow: true, // Conservatively say we do have overflow to avoid complexity. ); diff --git a/packages/flutter/test/widgets/sliver_resizing_header_test.dart b/packages/flutter/test/widgets/sliver_resizing_header_test.dart index aef1ab5229..ba59959f9d 100644 --- a/packages/flutter/test/widgets/sliver_resizing_header_test.dart +++ b/packages/flutter/test/widgets/sliver_resizing_header_test.dart @@ -357,4 +357,57 @@ void main() { await tester.pumpAndSettle(); expect(getHeaderHeight(), 200); }); + + testWidgets('SliverResizingHeader maxScrollObstructionExtent', (WidgetTester tester) async { + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: NestedScrollView( + headerSliverBuilder: + (BuildContext context, _) => [ + SliverOverlapAbsorber( + handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context), + sliver: const SliverResizingHeader( + minExtentPrototype: SizedBox(height: 100), + maxExtentPrototype: SizedBox(height: 300), + child: SizedBox.expand(child: Text('header')), + ), + ), + ], + body: Builder( + builder: + (BuildContext context) => CustomScrollView( + slivers: [ + SliverOverlapInjector( + handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context), + ), + SliverList( + delegate: SliverChildBuilderDelegate( + (BuildContext context, int index) => + SizedBox(height: 50, child: Text('$index')), + childCount: 100, + ), + ), + ], + ), + ), + ), + ), + ), + ); + + double getHeaderHeight() => tester.getSize(find.text('header')).height; + + expect(getHeaderHeight(), 300); + + // After scrolling down 150px, the header height becomes 150px + await tester.drag(find.byType(NestedScrollView), const Offset(0, -150)); + await tester.pumpAndSettle(); + expect(getHeaderHeight(), 150); + + // After scrolling down an additional 150px, the header height becomes 100px + await tester.drag(find.byType(NestedScrollView), const Offset(0, -150)); + await tester.pumpAndSettle(); + expect(getHeaderHeight(), 100); + }); }