vedartm / paginate_firestore

A flutter package to simplify pagination with firestore data 🗃
https://pub.dev/packages/paginate_firestore
MIT License
113 stars 136 forks source link

Duplication of document snapshot #72

Closed itssidhere closed 3 years ago

itssidhere commented 3 years ago

Due to this line in the PaginationCubit file, there are certain cases where the same document is included twice in the list.

emit(PaginationLoaded( documentSnapshots: previousList + newList, hasReachedEnd: newList.isEmpty, ));

vedartm commented 3 years ago

Hi @itssidhere. Can you share some code snippets demonstrating this issue?

itssidhere commented 3 years ago

I will share the same. But even without it it's evident when a document is changed in the stream(isLive: true).It's included in the new list as well as previous list so adding both list we will have duplicate elements.

My suggestion would be to do something like this

[newList + previousList].toSet().toList()

newList + previous list and not previousList+newList as the duplicate element's latest document is in newList so by toSet() only the newList element will be used.

Disadvantage of this is the order will be lost so the PaginateFirestore should return a builderFunction with the mutated list and not the individual document so that the user can restore the order of the list.

@excogitatr

vedartm commented 3 years ago

It's a good suggestion @itssidhere. If it is possible can you make PR with that changes and check if it is working as you intended?

itssidhere commented 3 years ago

@excogitatr Yes sure, I will make a pr asap.

vedartm commented 3 years ago

This is fixed in v1.01+1, thanks to @garrettApproachableGeek.

vedartm commented 3 years ago

Thanks for using the package. Feel free to reopen this if you face any similar issues.