0

I have a nosql database on Firebase with a collection of posts. Each post have a collection of comments.

When user add a new comment, ALL widgets reload (on posts list screen) and I want to only see comment adding to comment's list, not reloading all screen...

This is because I done it wrong code or wrong database?

I need to store comments on separate collection of posts like a relational database?

PS: I'm new to Flutter, Firebase and nosql databases

Maximiliano Sosa
  • 388
  • 1
  • 7
  • 18
  • Please show us your current working code, that will help us to help you. You are probably mutating the data that is used in `build()` inappropriately. Try using a stream builder if possible. – Joshua Chan Dec 08 '19 at 15:51

1 Answers1

2

You could make use of a concept called Lazy Loading. If you're using a list view to hold all of the posts, you could easily make it so that as the user scrolls, more posts get loaded and avoid loading all of the posts at once.

Lazy Loading concept: Flutter ListView lazy loading

You could also manually cut off the number of posts that it loads. If the user wants to see more, have a button at the bottom to load more posts.

A word of advice: The build methods should be cheap as they can be called at any time for any reason. Avoid having logic in the build methods and let that be in another class or at least separate the logic into different functions.

Benjamin
  • 5,783
  • 4
  • 25
  • 49