Fixing constraints.precedingScrollExtent passed to SliverPadding child (#49433)
This commit is contained in:
parent
bc8bfb10f8
commit
8b600032ee
@ -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,
|
||||
);
|
||||
|
@ -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: <Widget>[
|
||||
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<RenderBox>(find.byKey(key)).size.height,
|
||||
equals(570),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user