Skip to content

Commit

Permalink
Fix SliverPadding geometry (#106071)
Browse files Browse the repository at this point in the history
  • Loading branch information
Piinks authored Jun 16, 2022
1 parent f67d9b7 commit a783e42
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
13 changes: 12 additions & 1 deletion packages/flutter/lib/src/rendering/sliver_padding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
30 changes: 29 additions & 1 deletion packages/flutter/test/widgets/slivers_padding_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit a783e42

Please sign in to comment.