Return the correct number of semantic children for the ListView.separated constructor (#48741)
This commit is contained in:
parent
b3ea191407
commit
68d0c89ffc
@ -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 {
|
|||||||
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 {
|
|||||||
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() {
|
|||||||
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>[] }) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user