Skip to content

Commit 97b7700

Browse files
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]. <!-- Links --> [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 <victorsanniay@gmail.com>
1 parent 17e73f2 commit 97b7700

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

packages/flutter/lib/src/widgets/sliver_resizing_header.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ class _RenderSliverResizingHeader extends RenderSliver
223223
paintExtent: math.min(childExtent, remainingPaintExtent),
224224
layoutExtent: clampDouble(layoutExtent, 0, remainingPaintExtent),
225225
maxPaintExtent: childExtent,
226-
maxScrollObstructionExtent: childExtent,
226+
maxScrollObstructionExtent: minExtent,
227227
cacheExtent: calculateCacheOffset(constraints, from: 0.0, to: childExtent),
228228
hasVisualOverflow: true, // Conservatively say we do have overflow to avoid complexity.
229229
);

packages/flutter/test/widgets/sliver_resizing_header_test.dart

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,4 +357,57 @@ void main() {
357357
await tester.pumpAndSettle();
358358
expect(getHeaderHeight(), 200);
359359
});
360+
361+
testWidgets('SliverResizingHeader maxScrollObstructionExtent', (WidgetTester tester) async {
362+
await tester.pumpWidget(
363+
MaterialApp(
364+
home: Scaffold(
365+
body: NestedScrollView(
366+
headerSliverBuilder:
367+
(BuildContext context, _) => <Widget>[
368+
SliverOverlapAbsorber(
369+
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
370+
sliver: const SliverResizingHeader(
371+
minExtentPrototype: SizedBox(height: 100),
372+
maxExtentPrototype: SizedBox(height: 300),
373+
child: SizedBox.expand(child: Text('header')),
374+
),
375+
),
376+
],
377+
body: Builder(
378+
builder:
379+
(BuildContext context) => CustomScrollView(
380+
slivers: <Widget>[
381+
SliverOverlapInjector(
382+
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
383+
),
384+
SliverList(
385+
delegate: SliverChildBuilderDelegate(
386+
(BuildContext context, int index) =>
387+
SizedBox(height: 50, child: Text('$index')),
388+
childCount: 100,
389+
),
390+
),
391+
],
392+
),
393+
),
394+
),
395+
),
396+
),
397+
);
398+
399+
double getHeaderHeight() => tester.getSize(find.text('header')).height;
400+
401+
expect(getHeaderHeight(), 300);
402+
403+
// After scrolling down 150px, the header height becomes 150px
404+
await tester.drag(find.byType(NestedScrollView), const Offset(0, -150));
405+
await tester.pumpAndSettle();
406+
expect(getHeaderHeight(), 150);
407+
408+
// After scrolling down an additional 150px, the header height becomes 100px
409+
await tester.drag(find.byType(NestedScrollView), const Offset(0, -150));
410+
await tester.pumpAndSettle();
411+
expect(getHeaderHeight(), 100);
412+
});
360413
}

0 commit comments

Comments
 (0)