[bugfix] SliverGeometry is not valid: The "layoutExtent" is negative (#48947)
This commit is contained in:
@@ -1445,7 +1445,7 @@ class RenderSliverOverlapAbsorber extends RenderSliver with RenderObjectWithChil
|
||||
scrollExtent: childLayoutGeometry.scrollExtent - childLayoutGeometry.maxScrollObstructionExtent,
|
||||
paintExtent: childLayoutGeometry.paintExtent,
|
||||
paintOrigin: childLayoutGeometry.paintOrigin,
|
||||
layoutExtent: childLayoutGeometry.paintExtent - childLayoutGeometry.maxScrollObstructionExtent,
|
||||
layoutExtent: math.max(0, childLayoutGeometry.paintExtent - childLayoutGeometry.maxScrollObstructionExtent),
|
||||
maxPaintExtent: childLayoutGeometry.maxPaintExtent,
|
||||
maxScrollObstructionExtent: childLayoutGeometry.maxScrollObstructionExtent,
|
||||
hitTestExtent: childLayoutGeometry.hitTestExtent,
|
||||
|
||||
@@ -676,6 +676,12 @@ void main() {
|
||||
await gesture.up();
|
||||
debugDefaultTargetPlatformOverride = null;
|
||||
});
|
||||
|
||||
// Regression test for https://github.com/flutter/flutter/issues/39963.
|
||||
testWidgets('NestedScrollView with SliverOverlapAbsorber in or out of the first screen', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(const _TestLayoutExtentIsNegative(1));
|
||||
await tester.pumpWidget(const _TestLayoutExtentIsNegative(10));
|
||||
});
|
||||
}
|
||||
|
||||
class TestHeader extends SliverPersistentHeaderDelegate {
|
||||
@@ -692,3 +698,60 @@ class TestHeader extends SliverPersistentHeaderDelegate {
|
||||
@override
|
||||
bool shouldRebuild(TestHeader oldDelegate) => false;
|
||||
}
|
||||
|
||||
class _TestLayoutExtentIsNegative extends StatelessWidget {
|
||||
const _TestLayoutExtentIsNegative(this.widgetCountBeforeSliverOverlapAbsorber);
|
||||
final int widgetCountBeforeSliverOverlapAbsorber;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
home: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Test'),
|
||||
),
|
||||
body: NestedScrollView(
|
||||
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
|
||||
return <Widget>[
|
||||
...List<Widget>.generate(widgetCountBeforeSliverOverlapAbsorber, (_) {
|
||||
return SliverToBoxAdapter(
|
||||
child: Container(
|
||||
color: Colors.red,
|
||||
height: 200,
|
||||
margin:const EdgeInsets.all(20),
|
||||
),
|
||||
);
|
||||
},),
|
||||
SliverOverlapAbsorber(
|
||||
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
|
||||
sliver: SliverAppBar(
|
||||
pinned: true,
|
||||
forceElevated: innerBoxIsScrolled,
|
||||
backgroundColor: Colors.blue[300],
|
||||
title: Container(
|
||||
height: 50,
|
||||
child: const Center(
|
||||
child: Text('Sticky Header'),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
];
|
||||
},
|
||||
body: Container(
|
||||
height: 2000,
|
||||
margin: const EdgeInsets.only(top: 50),
|
||||
child: ListView(
|
||||
children: List<Widget>.generate(3, (_) {
|
||||
return Container(
|
||||
color: Colors.green[200],
|
||||
height: 200,
|
||||
margin: const EdgeInsets.all(20),
|
||||
);
|
||||
},),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user