From 8b600032eef74f6931179cbfcee5badcd014a590 Mon Sep 17 00:00:00 2001 From: Kate Lovett Date: Fri, 31 Jan 2020 12:58:03 -0800 Subject: [PATCH] Fixing constraints.precedingScrollExtent passed to SliverPadding child (#49433) --- .../lib/src/rendering/sliver_padding.dart | 1 + .../test/widgets/slivers_padding_test.dart | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/packages/flutter/lib/src/rendering/sliver_padding.dart b/packages/flutter/lib/src/rendering/sliver_padding.dart index 0a573a45a4..9891ce53ae 100644 --- a/packages/flutter/lib/src/rendering/sliver_padding.dart +++ b/packages/flutter/lib/src/rendering/sliver_padding.dart @@ -139,6 +139,7 @@ abstract class RenderSliverEdgeInsetsPadding extends RenderSliver with RenderObj remainingPaintExtent: constraints.remainingPaintExtent - calculatePaintOffset(constraints, from: 0.0, to: beforePadding), remainingCacheExtent: constraints.remainingCacheExtent - calculateCacheOffset(constraints, from: 0.0, to: beforePadding), crossAxisExtent: math.max(0.0, constraints.crossAxisExtent - crossAxisPadding), + precedingScrollExtent: beforePadding + constraints.precedingScrollExtent, ), parentUsesSize: true, ); diff --git a/packages/flutter/test/widgets/slivers_padding_test.dart b/packages/flutter/test/widgets/slivers_padding_test.dart index 305378a039..58728dc7a3 100644 --- a/packages/flutter/test/widgets/slivers_padding_test.dart +++ b/packages/flutter/test/widgets/slivers_padding_test.dart @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; @@ -423,4 +424,37 @@ void main() { const Rect.fromLTRB(0.0, -200.0, 800.0, 200.0), ); }); + + testWidgets('SliverPadding includes preceding padding in the precedingScrollExtent provided to child', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/49195 + final UniqueKey key = UniqueKey(); + await tester.pumpWidget(Directionality( + textDirection: TextDirection.ltr, + child: CustomScrollView( + slivers: [ + SliverPadding( + padding: const EdgeInsets.only(top: 30), + sliver: SliverFillRemaining( + hasScrollBody: false, + child: Container( + key: key, + color: Colors.red, + ), + ) + ), + ] + ), + )); + await tester.pump(); + + // The value of 570 is expected since SliverFillRemaining will fill all of + // the space available to it. In this test, the extent of the viewport is + // 600 pixels. If the SliverPadding widget provides the right constraints + // to SliverFillRemaining, with 30 pixels preceding it, it should only have + // a height of 570. + expect( + tester.renderObject(find.byKey(key)).size.height, + equals(570), + ); + }); }