-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Force onModelReady #15
Comments
Hi there, This architecture was specifically set up to have a function that can be called once upon the creation of a widget. So in this case you'd have to extend or change the architecture for your purpose. If you want to call a function on the model every time it's rebuilt you should remove the model from your base widget state and pass it in directly to the builder function using widget.model, instead of setting it in the init function to a local long living model. Then on the outside you'll pass it in like this, and call your fetchData after it's been constructed. AppModule module = (...)
BaseWidget<MyPageViewModel>(
model: MyPageViewModel(api: Provider.of(context))..fetchData(module),
builder: ...
) |
Hi, Thanks for your quick response. I am trying to do what you suggest:
As you can see, my way of implementing this is to add a boolean variable |
Mmmmmmmm. I think you should split up this here
Because what I'm seeing there is that when widget.fetchOnBuild is supplied it will return that value. If not it will return false, which will then return the model. So it'll either return true if fetchOnBuild is supplied or the model internally, but I can't see it returning your widget.model. Split that up and make it more readable.
Something like that maybe? |
What that line says is that it returns widget.model when fetchOnBuild is true and it returns model if fetchOnBuild is false or undefined. Anyway, I ended up implementing another function next to OnModelReady
Thank you very much for your help and for all your work! We have chosen your arquitecture for a complex, production-ready full application and my team is really happy with it. Congratulations! |
Haha I struggle with code like that so I completely miss read it . Sometimes it's a bit too short hand. That's super awesome man!! I'm so happy that I could help. I like the approach you took above. I didn't think of that solution and I like it! Thanks for sharing |
Hi @eskalera , Could you please do an example of an implementation of this BaseView and data fetching? I'm trying to wrap my head but I don't know what parameters I need to pass. Regards, |
Hi @ericklhe , I sure do. Here is an example of the build method of a widget:
It's just the exact same as proposed by @FilledStacks , just changing |
I am using your BaseModel-BaseWidget arquitecture from 014-provider-v3-updates.
I have the following:
When the module changes I wanted my data to be fetched again, but I see the BaseWidget is only being rebuilt, without calling the onModelReady. I guess this is because the viewModel has not been disposed, right?
How can I approach these scenario?
The text was updated successfully, but these errors were encountered: