Unverified Commit 8a48a278 authored by Kate Lovett's avatar Kate Lovett Committed by GitHub

Performance Improvement for SliverFillRemaining (#44471)

parent cd94cd88
......@@ -157,16 +157,15 @@ class RenderSliverFillRemaining extends RenderSliverSingleBoxAdapter {
parentUsesSize: true,
);
} else if (child != null) {
child.layout(constraints.asBoxConstraints(), parentUsesSize: true);
switch (constraints.axis) {
case Axis.horizontal:
childExtent = child.size.width;
childExtent = child.getMaxIntrinsicWidth(constraints.crossAxisExtent);
break;
case Axis.vertical:
childExtent = child.size.height;
childExtent = child.getMaxIntrinsicHeight(constraints.crossAxisExtent);
break;
}
if (constraints.precedingScrollExtent > constraints.viewportMainAxisExtent || childExtent > extent)
extent = childExtent;
if (maxExtent < extent)
......@@ -179,6 +178,8 @@ class RenderSliverFillRemaining extends RenderSliverSingleBoxAdapter {
),
parentUsesSize: true,
);
} else {
child.layout(constraints.asBoxConstraints(), parentUsesSize: true);
}
}
......
......@@ -70,12 +70,18 @@ void main() {
child: Container(
color: Colors.amber,
height: 150.0,
width: 150,
),
);
Widget boilerplate(List<Widget> slivers, {ScrollController controller}) {
Widget boilerplate(
List<Widget> slivers, {
ScrollController controller,
Axis scrollDirection = Axis.vertical,
}) {
return MaterialApp(
home: Scaffold(
body: CustomScrollView(
scrollDirection: scrollDirection,
slivers: slivers,
controller: controller,
),
......@@ -128,8 +134,12 @@ void main() {
),
];
await tester.pumpWidget(boilerplate(slivers));
final RenderBox box = tester.renderObject<RenderBox>(find.byType(Container).last);
RenderBox box = tester.renderObject<RenderBox>(find.byType(Container).last);
expect(box.size.height, equals(450));
await tester.pumpWidget(boilerplate(slivers, scrollDirection: Axis.horizontal));
box = tester.renderObject<RenderBox>(find.byType(Container).last);
expect(box.size.width, equals(650));
});
testWidgets('child with size is sized by extent when false', (WidgetTester tester) async {
......@@ -158,6 +168,9 @@ void main() {
final Finder button = find.byType(RaisedButton);
expect(tester.getBottomLeft(button).dy, equals(600.0));
expect(tester.getCenter(button).dx, equals(400.0));
await tester.pumpWidget(boilerplate(slivers, scrollDirection: Axis.horizontal));
expect(tester.renderObject<RenderBox>(find.byKey(key)).size.width, equals(650));
});
testWidgets('extent is overridden by child with larger size when false', (WidgetTester tester) async {
......@@ -168,12 +181,17 @@ void main() {
child: Container(
color: Colors.blue,
height: 600,
width: 1000,
),
),
];
await tester.pumpWidget(boilerplate(slivers));
final RenderBox box = tester.renderObject<RenderBox>(find.byType(Container).last);
RenderBox box = tester.renderObject<RenderBox>(find.byType(Container).last);
expect(box.size.height, equals(600));
await tester.pumpWidget(boilerplate(slivers, scrollDirection: Axis.horizontal));
box = tester.renderObject<RenderBox>(find.byType(Container).last);
expect(box.size.width, equals(1000));
});
testWidgets('extent is overridden by child size if precedingScrollExtent > viewportMainAxisExtent when false', (WidgetTester tester) async {
......@@ -313,7 +331,6 @@ void main() {
final Finder button = find.byType(RaisedButton);
expect(tester.getBottomLeft(button).dy, equals(550.0));
expect(tester.getCenter(button).dx, equals(400.0));
debugDefaultTargetPlatformOverride = null;
// Drag for overscroll
await tester.drag(find.byType(Scrollable), const Offset(0.0, -50.0));
......@@ -418,7 +435,6 @@ void main() {
final Finder button = find.byType(RaisedButton);
expect(tester.getBottomLeft(button).dy, equals(550.0));
expect(tester.getCenter(button).dx, equals(400.0));
debugDefaultTargetPlatformOverride = null;
await tester.drag(find.byType(Scrollable), const Offset(0.0, -50.0));
await tester.pump();
......
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