简体   繁体   中英

What is the best practice for fetching posts in flutter from MySQL database?

I'm creating an application where users can create posts. I have a database that contains all the posts' details however, I want to get all the posts in the database and present them on one page in the app. I was thinking to get all the posts and save them in a list of Post objects and then present them all using ListView but I thought that this is impractical and could make the screen loads slower. Is there a better way to do that?

Well, I meant it depends on how many posts will be shown on one page. If it's one million posts, then of course you can not retrieve them all at once and save them in a list, but rather retrieve them in small packages as the user is scrolling. If however, the number of posts you show on one page is moderate, the way you outlined in your question is perfectly fine. And another point is, that loading and saving the posts will not make the screen load slower. Because normally you would just wrap the ListView with a FutureBuilder and display some LoadingAnimation while the posts are being loaded. So basically the posts are retrieved and loaded after the screen has been loaded.

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