ListTile.divideTiles only run Iterable once (#78879)
This commit is contained in:
@@ -980,11 +980,11 @@ class ListTile extends StatelessWidget {
|
||||
assert(tiles != null);
|
||||
assert(color != null || context != null);
|
||||
|
||||
if (tiles.isEmpty)
|
||||
return;
|
||||
|
||||
final Iterator<Widget> iterator = tiles.iterator;
|
||||
final bool isNotEmpty = iterator.moveNext();
|
||||
final bool hasNext = iterator.moveNext();
|
||||
|
||||
if (!hasNext)
|
||||
return;
|
||||
|
||||
final Decoration decoration = BoxDecoration(
|
||||
border: Border(
|
||||
@@ -1001,7 +1001,7 @@ class ListTile extends StatelessWidget {
|
||||
);
|
||||
tile = iterator.current;
|
||||
}
|
||||
if (isNotEmpty)
|
||||
if (hasNext)
|
||||
yield tile;
|
||||
}
|
||||
|
||||
|
||||
@@ -257,6 +257,20 @@ void main() {
|
||||
expect(output, isEmpty);
|
||||
});
|
||||
|
||||
testWidgets('ListTile.divideTiles only runs the generator once', (WidgetTester tester) async {
|
||||
// Regression test for https://github.com/flutter/flutter/pull/78879
|
||||
int callCount = 0;
|
||||
Iterable<Widget> generator() sync* {
|
||||
callCount += 1;
|
||||
yield const Text('');
|
||||
yield const Text('');
|
||||
}
|
||||
|
||||
final List<Widget> output = ListTile.divideTiles(tiles: generator(), color: Colors.grey).toList();
|
||||
expect(output, hasLength(2));
|
||||
expect(callCount, 1);
|
||||
});
|
||||
|
||||
testWidgets('ListTileTheme', (WidgetTester tester) async {
|
||||
final Key titleKey = UniqueKey();
|
||||
final Key subtitleKey = UniqueKey();
|
||||
|
||||
Reference in New Issue
Block a user