You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
APIs that take List<X> should take Iterable<X> #247
I'm often finding myself using List.map to turn a list of data objects into a list of widgets as children or menu items. Every time so far I've forgotten to .toList(). Is there a reason that the APIs that need a list of things don't just take an Iterable?
Well, one reason is that we need to have a list we can iterate over. If all we were getting was an Iterable, then every time one was passed in, we'd have to call toList() on it, and that would basically double the number of copies of all the widget lists.
I don't really see a way to do this unless there's a way to get from a <Widget>[] literal to a List<Widget> via an Iterable<Widget> argument without paying the cost of a copy.
We've decided not to do this in general. There are some specific places that accept Iterable because they can work lazily. In the cases, however, we'd need to pull everything from the iterable anyhow and it's more efficient if we do that as early in the processing as possible (e.g., just after the iterable is created with something like map).
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.
Activity
FlutterIssues commentedon Nov 9, 2015
Monday Nov 02, 2015 at 23:56 GMT
/cc @Hixie
We tried using Iterable at one point, but I don't remember when we ended up going back to List. Ian do you remember?
FlutterIssues commentedon Nov 9, 2015
Tuesday Nov 03, 2015 at 00:09 GMT
I forget the details, but it was in fn2, so it might no longer matter. We can try again.
FlutterIssues commentedon Nov 9, 2015
Tuesday Nov 03, 2015 at 01:54 GMT
Bonus: using Iterable means you can use
yield:)Hixie commentedon Dec 12, 2015
Well, one reason is that we need to have a list we can iterate over. If all we were getting was an Iterable, then every time one was passed in, we'd have to call toList() on it, and that would basically double the number of copies of all the widget lists.
Hixie commentedon Dec 12, 2015
I don't really see a way to do this unless there's a way to get from a
<Widget>[]literal to aList<Widget>via anIterable<Widget>argument without paying the cost of a copy.abarth commentedon Jan 11, 2016
We do this for ScrollableList now. We actually can pull the iterator lazily in many cases too.
abarth commentedon Oct 16, 2016
We've decided not to do this in general. There are some specific places that accept Iterable because they can work lazily. In the cases, however, we'd need to pull everything from the iterable anyhow and it's more efficient if we do that as early in the processing as possible (e.g., just after the iterable is created with something like map).
github-actions commentedon Aug 17, 2021
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.