I have a use case, where is seems like a combination of read and select would be nice. Or maybe there is another way I'm not aware of.
I basically want to bind a callback when the property on some provided model changes, but I don't want to trigger a rebuild, instead I just want to do something.
In this case, if my open SearchPanel, notices that AppModel.currentPage has changed, I would like the SearchPanel to call close itself.
I'm not sure how to set that up with Provider, short of doing something like this:
@override
void initState() {
AppModel m = context.read<AppModel>();
PageType prevPage = m.currentMainPage;
m.addListener(() {
if(m.currentMainPage != prevPage){
handleClosePressed(false);//Close without submitting
}
prevPage = m.currentMainPage;
});
super.initState();
}
Something like this would be pretty handy:
void initState() {
context.selectChange<AppModel, PageType>((m)=>m.currentMainPage, (pt){
handleClosePressed(false);
});
super.initState();
});
This is something that I've been thinking for a while too:
Adding a context.onChange<T>.
The biggest issue is _how to do that_.
I don't see how to do such thing without relying on flutter_hooks.
Most helpful comment
This is something that I've been thinking for a while too:
Adding a
context.onChange<T>.The biggest issue is _how to do that_.
I don't see how to do such thing without relying on flutter_hooks.