Unverified Commit a783e422 authored by Kate Lovett's avatar Kate Lovett Committed by GitHub

Fix SliverPadding geometry (#106071)

parent f67d9b75
......@@ -119,10 +119,21 @@ abstract class RenderSliverEdgeInsetsPadding extends RenderSliver with RenderObj
final double mainAxisPadding = this.mainAxisPadding;
final double crossAxisPadding = this.crossAxisPadding;
if (child == null) {
final double paintExtent = calculatePaintOffset(
constraints,
from: 0.0,
to: mainAxisPadding,
);
final double cacheExtent = calculateCacheOffset(
constraints,
from: 0.0,
to: mainAxisPadding,
);
geometry = SliverGeometry(
scrollExtent: mainAxisPadding,
paintExtent: math.min(mainAxisPadding, constraints.remainingPaintExtent),
paintExtent: math.min(paintExtent, constraints.remainingPaintExtent),
maxPaintExtent: mainAxisPadding,
cacheExtent: cacheExtent,
);
return;
}
......
......@@ -271,6 +271,34 @@ void main() {
expect(tester.renderObject<RenderBox>(find.text('x')).localToGlobal(Offset.zero), const Offset(0.0, 200.0));
});
testWidgets('SliverPadding with no child reports correct geometry as scroll offset changes', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/64506
final ScrollController controller = ScrollController();
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: CustomScrollView(
controller: controller,
slivers: const <Widget>[
SliverPadding(padding: EdgeInsets.all(100.0)),
SliverToBoxAdapter(child: SizedBox(width: 400.0, height: 400.0, child: Text('x'))),
],
),
),
);
expect(tester.renderObject<RenderBox>(find.text('x')).localToGlobal(Offset.zero), const Offset(0.0, 200.0));
expect(
tester.renderObject<RenderSliverPadding>(find.byType(SliverPadding)).geometry!.paintExtent,
200.0,
);
controller.jumpTo(50.0);
await tester.pump();
expect(
tester.renderObject<RenderSliverPadding>(find.byType(SliverPadding)).geometry!.paintExtent,
150.0,
);
});
testWidgets('Viewport+SliverPadding changing padding', (WidgetTester tester) async {
await tester.pumpWidget(
Directionality(
......@@ -366,7 +394,7 @@ void main() {
),
),
);
expect(tester.renderObject<RenderSliverPadding>(find.byType(SliverPadding)).afterPadding, 1.0);
expect(tester.renderObject<RenderSliverPadding>(find.byType(SliverPadding, skipOffstage: false)).afterPadding, 1.0);
});
testWidgets('SliverPadding propagates geometry offset corrections', (WidgetTester tester) async {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment