ViewModel not re-initialized on notify by ReactiveServiceMixin
Hi, I'm pretty new to the stacked arch and so far I like it very much. Currently, I try to implement something like this:
FooService (ReactiveServiceMixin) BarViewModel (ReactiveViewModel) StatelessWidget FooBarView (Reactive View Model Builder)
Now I call notifiyListeners() in my FooService. This triggers a rebuild of the build method from FooBarView, which is correct. But now I need BarViewModel to be re-initialized, after the rebuild is triggered... I don't want to call my BarViewModel.notifyListeners() inside the build of the StatelessWidget, because this will obviously be recursive then.
Is there any advice?😊
Thank you very much in advance, this is my first question for this repo. Greetings from germany!
@d3tr0id Awesome. I'm glad you like it.
it won't rebuild. I always get questions from both sides, sometimes from the same people 😄
- When I rebuild my view, no other widgets should rebuild
- When I rebuild my view, all other widgets beneath it should be rebuilt
But we've opted for the most popular no.1. Which is to not rebuild all the widgets every time. I also think you're using initialise wrong here.
Do you want onViewModelReady to fire again, do you want your initialize function in the ViewModel to run again or do you just want the builder to fire again?
Hi, first of all thank you for your response!
I want to call a function in my ViewModel when the View's build is triggered (by the ReactiveServiceMixin). Warning, the function I want to call, uses notifyListeners().
Thank you for your time 😊
hey, that's not a good idea. I'd suggest you pass a callback function to your service and call that. You wouldn't need to do what you're trying to do because it's doing the same things twice. You want to call a function when you notifylisteners but then you notifyListeners in the function you want to call.
What are you trying to do. I'm sure there's a simpler way to do it.