-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Description
It's a bit late to the party, since NNBD migration was done a long time ago.
But it seems that the migration process broke ListView.builder's itemBuilder ability to return null;
Steps to Reproduce
We used to be able to write the following:
ListView.builder(
// no item count
itemBuilder: (context, index) {
if (condition) return null;
return Item();
}
)Expected results:
Before NNBD migration, this code would render Item() until condition is true, at which point the list ends (similar to as it we reached the end of itemCount)
Actual results:
The code doesn't compile as itemBuilder doesn't allow returning null anymore.
Browsing through the git blames, it seems that this was removed by mistake.
It probably didn't have a test and slipped through the review process because of the NNBD migration of IndexedItemBuilder.
This issue #58371 (comment) in particular shows that returning null was a supported behavior.
Similarly, SliverChildBuilderDelegate.build (the delegate that implements ListView.builder) still allows returning null.
So returning null is still technically supported, just not with the .builder constructor