简体   繁体   中英

Dynamically End Flutter ListView

I have a ListView widget (using ListView.builder(...) ) that displays a long list of paginated query results that are lazily fetched from a remote db. Because the results are paginated, I don't know how many results there are until the user has scrolled through them all.

How do I set the itemCount (or otherwise fix the length) of a dynamic ListView after the ListView has been constructed? I could replace the ListView with a new one with a set itemCount once the itemCount is known, but that sounds really sloppy and potentially expensive (I assume flutter isn't smart enough to reuse the old ListView's children?).

I decided that there was a fundamental issue with my approach: a user could scroll arbitrarily far (past the limit of the list) because the actual length of the list is not known until the stream is done. So I revised my approach (in line with Aknahseh_tg's suggestion) such that the user see's a fixed list the length of the currently loaded elements with a final placeholder element that says "loading" at the end if the stream has not emitted a 'Done' event yet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM