diff --git a/packages/flutter/lib/src/rendering/sliver_padding.dart b/packages/flutter/lib/src/rendering/sliver_padding.dart index f78b401ada79..34fadde636bd 100644 --- a/packages/flutter/lib/src/rendering/sliver_padding.dart +++ b/packages/flutter/lib/src/rendering/sliver_padding.dart @@ -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; } diff --git a/packages/flutter/test/widgets/slivers_padding_test.dart b/packages/flutter/test/widgets/slivers_padding_test.dart index c1562b153a89..619f024be53f 100644 --- a/packages/flutter/test/widgets/slivers_padding_test.dart +++ b/packages/flutter/test/widgets/slivers_padding_test.dart @@ -271,6 +271,34 @@ void main() { expect(tester.renderObject(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 [ + SliverPadding(padding: EdgeInsets.all(100.0)), + SliverToBoxAdapter(child: SizedBox(width: 400.0, height: 400.0, child: Text('x'))), + ], + ), + ), + ); + expect(tester.renderObject(find.text('x')).localToGlobal(Offset.zero), const Offset(0.0, 200.0)); + expect( + tester.renderObject(find.byType(SliverPadding)).geometry!.paintExtent, + 200.0, + ); + controller.jumpTo(50.0); + await tester.pump(); + expect( + tester.renderObject(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(find.byType(SliverPadding)).afterPadding, 1.0); + expect(tester.renderObject(find.byType(SliverPadding, skipOffstage: false)).afterPadding, 1.0); }); testWidgets('SliverPadding propagates geometry offset corrections', (WidgetTester tester) async {