Unverified Commit 68d0c89f authored by rami-a's avatar rami-a Committed by GitHub

Return the correct number of semantic children for the ListView.separated constructor (#48741)

parent b3ea1914
...@@ -1051,7 +1051,7 @@ class ListView extends BoxScrollView { ...@@ -1051,7 +1051,7 @@ class ListView extends BoxScrollView {
} }
return widget; return widget;
}, },
childCount: _computeSemanticChildCount(itemCount), childCount: _computeActualChildCount(itemCount),
addAutomaticKeepAlives: addAutomaticKeepAlives, addAutomaticKeepAlives: addAutomaticKeepAlives,
addRepaintBoundaries: addRepaintBoundaries, addRepaintBoundaries: addRepaintBoundaries,
addSemanticIndexes: addSemanticIndexes, addSemanticIndexes: addSemanticIndexes,
...@@ -1069,7 +1069,7 @@ class ListView extends BoxScrollView { ...@@ -1069,7 +1069,7 @@ class ListView extends BoxScrollView {
shrinkWrap: shrinkWrap, shrinkWrap: shrinkWrap,
padding: padding, padding: padding,
cacheExtent: cacheExtent, cacheExtent: cacheExtent,
semanticChildCount: _computeSemanticChildCount(itemCount), semanticChildCount: itemCount,
); );
/// Creates a scrollable, linear array of widgets with a custom child model. /// Creates a scrollable, linear array of widgets with a custom child model.
...@@ -1215,8 +1215,8 @@ class ListView extends BoxScrollView { ...@@ -1215,8 +1215,8 @@ class ListView extends BoxScrollView {
properties.add(DoubleProperty('itemExtent', itemExtent, defaultValue: null)); properties.add(DoubleProperty('itemExtent', itemExtent, defaultValue: null));
} }
// Helper method to compute the semantic child count for the separated constructor. // Helper method to compute the actual child count for the separated constructor.
static int _computeSemanticChildCount(int itemCount) { static int _computeActualChildCount(int itemCount) {
return math.max(0, itemCount * 2 - 1); return math.max(0, itemCount * 2 - 1);
} }
} }
......
...@@ -304,6 +304,54 @@ void main() { ...@@ -304,6 +304,54 @@ void main() {
expect(find.text('s5'), findsNothing); expect(find.text('s5'), findsNothing);
expect(find.text('i6'), findsNothing); expect(find.text('i6'), findsNothing);
}); });
testWidgets('ListView.separated uses correct semanticChildCount', (WidgetTester tester) async {
Widget buildFrame({int itemCount}) {
return Directionality(
textDirection: TextDirection.ltr,
child: ListView.separated(
itemCount: itemCount,
itemBuilder: (BuildContext context, int index) {
return SizedBox(
height: 100.0,
child: Text('i$index'),
);
},
separatorBuilder: (BuildContext context, int index) {
return SizedBox(
height: 10.0,
child: Text('s$index'),
);
},
),
);
}
Scrollable scrollable() {
return tester.widget<Scrollable>(
find.descendant(
of: find.byType(ListView),
matching: find.byType(Scrollable),
),
);
}
await tester.pumpWidget(buildFrame(itemCount: 0));
expect(scrollable().semanticChildCount, 0);
await tester.pumpWidget(buildFrame(itemCount: 1));
expect(scrollable().semanticChildCount, 1);
await tester.pumpWidget(buildFrame(itemCount: 2));
expect(scrollable().semanticChildCount, 2);
await tester.pumpWidget(buildFrame(itemCount: 3));
expect(scrollable().semanticChildCount, 3);
await tester.pumpWidget(buildFrame(itemCount: 4));
expect(scrollable().semanticChildCount, 4);
});
} }
void check({ List<int> visible = const <int>[], List<int> hidden = const <int>[] }) { void check({ List<int> visible = const <int>[], List<int> hidden = const <int>[] }) {
......
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