Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add context.selectChange #397

Open
esDotDev opened this issue Mar 30, 2020 · 3 comments
Open

Add context.selectChange #397

esDotDev opened this issue Mar 30, 2020 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@esDotDev
Copy link

esDotDev commented Mar 30, 2020

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();
});
@rrousselGit
Copy link
Owner

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.

@rrousselGit rrousselGit added the enhancement New feature or request label Apr 11, 2020
@rshrc
Copy link

rshrc commented Oct 7, 2021

@rrousselGit whats the workaround that I am missing on? are there any updates on this feature request?

@rrousselGit
Copy link
Owner

As said previously, I have no idea on how to implement this. I'm open to suggestions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants