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.

Answered By – TheUltimateOptimist

Answer Checked By – Pedro (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *