Closed dsourav closed 4 years ago
Then you should remove the .length chat if you want it otherwise
Then you should remove the .length chat if you want it otherwise
It won't work until it will be listened from below
pagePostsQuery.snapshots().listen((postsSnapshot) {
if (postsSnapshot.documents.isNotEmpty) {
var posts = postsSnapshot.documents
.map((snapshot) => Post.fromMap(snapshot.data, snapshot.documentID))
.where((mappedItem) => mappedItem.title != null)
.toList();
}
}
@dsourav I don't know if you're asking me a question or telling me how you fixed it
@dsourav I don't know if you're asking me a question or telling me how you fixed it
I am asking you question buddy. The way you're saying isn't working. Don't you think it needs to be fixed.
@dsourav in this repo no, it's an example to show how to do pagination with real time data. that's all that it should focus on. In your own code if you're using it then yes. You should fix it up. Figure out how to make it update when there's no documents and do that. i would assume updating even when the length is 0 should work fine. but I still don't understand your comment about listening above so i don't know if you tried it or not.
@dsourav in this repo no, it's an example to show how to do pagination with real time data. that's all that it should focus on. In your own code if you're using it then yes. You should fix it up. Figure out how to make it update when there's no documents and do that. i would assume updating even when the length is 0 should work fine. but I still don't understand your comment about listening above so i don't know if you tried it or not.
I said about listening to the stream.
if (postsSnapshot.documents.isNotEmpty)
{
...
}
You are adding value to the stream controller only when the documents aren't empty. So if there's no document then you aren't adding any value to the stream controller. Then how the length is 0 will work.
Aaah, I see. Then You can just always set the value even when there's no documents.
var pagePostsQuery = _postsCollectionReference
.orderBy('title')
.limit(PostsLimit)
Here pagePostsQuery contains only the paginated data. Not the entire documents in a collection. So we can't use it to check if the collection is empty.
@dsourav And do we want to check if the collection is empty?
@dsourav And do we want to check if the collection is empty?
Yes... exactly..
@dsourav haha i don't know what's going on man. I'm not changing the tutorial code. The concept i was teaching is pagination with firebase realtime data. The code does that. Any other implementation details is up to the dev applying this pattern. So you'll have to check if it's empty, or not check I don't quite know what you're asking me for. It's hard to follow along with the short replies and explanations of things and I think there might be a language barrier as well.
Real time database means it will listen changes of data whenever any changes happens to the database...so if we delete all the documents from a collection then it also needs to be listened. Since your tutorial code represent the term realtime pagination then it needs to be fixed ... otherwise you can't tell it a real time pagination.
Well I definitely consider it a real-time pagination as you've seen it works. The details like removing all the documents will be up to you to implement. If I had to cover every scenario for the tutorial with my free time it would have been a 1-2 hour tutorial which would take me a lot longer than 24 hours to make.
It's up to you to work on the pattern and add your implementation details based on your need. I show high level solutions to problems, details are up to the dev to implement.
I think it's an issue that's why a let you know about it. If you think you are okay with it and you don't want to make any changes it's totally up to you.
I see. I'm happy with the way that it is. I won't be making changes to any old code tutorials. I can't even finish the new ones haha. You're always welcome to fix it and make a PR.
This code only can update the UI if the collection isn't empty