Unverified Commit b63bcaa3 authored by Xavier H's avatar Xavier H Committed by GitHub

ListTile.divideTiles only run Iterable once (#78879)

parent 69f2f8a1
......@@ -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();
......
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