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