Unverified Commit a52f0f77 authored by chunhtai's avatar chunhtai Committed by GitHub

Fixes sliver list does not layout firstchild when child reordered (#36493)

parent 2338576a
......@@ -103,6 +103,10 @@ class RenderSliverList extends RenderSliverMultiBoxAdaptor {
childParentData.layoutOffset = 0.0;
if (scrollOffset == 0.0) {
// insertAndLayoutLeadingChild only lays out the children before
// firstChild. In this case, nothing has been laid out. We have
// to lay out firstChild manually.
firstChild.layout(childConstraints, parentUsesSize: true);
earliestUsefulChild = firstChild;
leadingChildWithLayout = earliestUsefulChild;
trailingChildWithLayout ??= earliestUsefulChild;
......
......@@ -4,6 +4,7 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter/material.dart';
void main() {
testWidgets('SliverList reverse children (with keys)', (WidgetTester tester) async {
......@@ -144,6 +145,52 @@ void main() {
expect(find.text('Tile 18'), findsOneWidget);
expect(find.text('Tile 19'), findsNothing);
});
testWidgets('SliverList should layout first child in case of child reordering', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/35904.
List<String> items = <String>['1', '2'];
await tester.pumpWidget(_buildSliverListRenderWidgetChild(items));
await tester.pumpAndSettle();
expect(find.text('Tile 1'), findsOneWidget);
expect(find.text('Tile 2'), findsOneWidget);
items = items.reversed.toList();
await tester.pumpWidget(_buildSliverListRenderWidgetChild(items));
await tester.pumpAndSettle();
expect(find.text('Tile 1'), findsOneWidget);
expect(find.text('Tile 2'), findsOneWidget);
});
}
Widget _buildSliverListRenderWidgetChild(List<String> items) {
return MaterialApp(
home: Directionality(
textDirection: TextDirection.ltr,
child: Material(
child: Container(
height: 500,
child: CustomScrollView(
controller: ScrollController(),
slivers: <Widget>[
SliverList(
delegate: SliverChildListDelegate(
items.map<Widget>((String item) {
return Chip(
key: Key(item),
label: Text('Tile $item'),
);
}).toList(),
),
),
],
),
),
),
),
);
}
Widget _buildSliverList({
......
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