brianegan / flutter_redux

A library that connects Widgets to a Redux Store
MIT License
1.65k stars 219 forks source link

onWillChange and onDidChange called twice after state update #238

Closed Lyba97 closed 2 years ago

Lyba97 commented 2 years ago

I am having an issue with StoreConnector. I have a login page with a button that shows a popup if a specific condition is met. I have put the condition variable in the Store. When that variable turns true only then should the popup show. Every time there is a change in the state this onWillChange is called twice. I do not want it to run twice as my other logic also runs twice on state change. I am adding a screenshot of some print log that confirms that the method is called twice on each change.

Screenshot 2022-08-27 at 4 01 28 PM
brianegan commented 2 years ago

Thanks for the report. From the print statements, I can see that onWillChange is indeed called twice. However, it's hard to debug this issue with a screenshot.

That could happen for a number of reasons. For example, do you have two onWillChange callbacks in different parts of your app?

Therefore, do you have a small bit of code you can share which reproduces the issue? I have some tests in place that verify onWillChange is only called once, but I might have missed an edge case.

A small, reproducible sample app or bit of code is the only way I could help discover the issue.

Thanks!

On Sat, Aug 27, 2022 at 12:07 Lyba Kashif @.***> wrote:

I am having an issue with StoreConnector. I have a login page with a button that shows a popup if a specific condition is met. I have put the condition variable in the Store. When that variable turns true only then should the popup show. Every time there is a change in the state this onWillChange is called twice. I do not want it to run twice as my other logic also runs twice on state change. I am adding a screenshot of some print log that confirms that the method is called twice on each change. [image: Screenshot 2022-08-27 at 4 01 28 PM] https://user-images.githubusercontent.com/63864699/187027443-fa766f8e-b62b-4386-aac6-8fad2e2e30e8.png

— Reply to this email directly, view it on GitHub https://github.com/brianegan/flutter_redux/issues/238, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA65DHU5HPV37S3UVOIAXTV3HZIJANCNFSM57ZE3OIQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

Lyba97 commented 2 years ago

Hi, @brianegan Thank you for your response. I got to know that I was not overriding == and hashcode methods for the VM and hence onWillChange and onDidChange were being called twice. It is solved by overriding the methods in the relevant ViewModel class when distinct is true. You can mark it as complete :)