Code Monkey home page Code Monkey logo

Comments (5)

TarekkMA avatar TarekkMA commented on June 23, 2024

Hello @abineshPalanisamy Thank you for sharing an issue. I see that _buildListView is being called in build. and it has some logic to add to the list employeeData so it can result in duplicate data.

Can you refactor this and test atain?

from flutterfire.

abineshPalanisamy avatar abineshPalanisamy commented on June 23, 2024

Hi @TarekkMA

When setState is called, snapshot.data.docChanges gets reinitialized and behaves as if it is the initial loading by providing all the documents in the Firestore collection with the type DocumentChangeType.added. This can cause duplicate values to be built. On initial loading of the application, snapshot.data.docChanges correctly provides documents with DocumentChangeType.added, which is expected and fine. However, upon calling setState, it again provides all documents in the Firestore collection as snapshot.data.docChanges with DocumentChangeType.added, even if there have been no changes or modifications in Firestore.

We performed logic in the _buildListView method based on snapshot.data.docChanges. Therefore, I concluded that snapshot.data.docChanges behaves improperly when setState is called in the application. This improper functioning leads to duplicate values.

Regards,
Abinesh P

from flutterfire.

TarekkMA avatar TarekkMA commented on June 23, 2024

Calling add in build method will lead to duplicate values, Can you construct the list employeeData only once and try again?

from flutterfire.

google-oss-bot avatar google-oss-bot commented on June 23, 2024

Hey @abineshPalanisamy. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

from flutterfire.

abineshPalanisamy avatar abineshPalanisamy commented on June 23, 2024

Hi @TarekkMA ,

I believe that the add method is not the cause of the duplicate values. Based on snapshot.data.docChanges, we have added the data from Firestore to the ListView.Builder. Therefore, an improper function of snapshot.data.docChanges leads to the duplicate values.

According to the previous response, when setState is called, snapshot.data.docChanges gets reinitialized and behaves as if it is the initial loading by providing all the documents in the Firestore collection with the type DocumentChangeType.added. This is the root cause of the issue. My concern is why snapshot.data.docChanges gets reinitialized and behaves as if it is the initial loading when setState is called in the application. snapshot.data.docChanges should maintain its state even when we rebuild the app by calling setState.

Regards,
Abinesh P

from flutterfire.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.