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

Is there any way to use viewModel in didUpdateWidget? #178

Open
AsheKR opened this issue Apr 2, 2023 · 1 comment
Open

Is there any way to use viewModel in didUpdateWidget? #178

AsheKR opened this issue Apr 2, 2023 · 1 comment

Comments

@AsheKR
Copy link

AsheKR commented Apr 2, 2023

When the arguments received from the widget changed, we wanted to clear the existing listener for the pagingController and populate a new one. How can i do this?

@override
void didUpdateWidget(convariant MyWidget oldWidget) {
  super.didUpdateWidget(oldWidget);
  
  if (oldWidget.path != widget.path) {
    _pagingController.removePageRequestListener(_pageRequestListener!);
    _pageRequestListener = null;

    _pageRequestListener = (pageKey) async {
      // This is where we use viewModel.
    }

    _pagingController.addPageRequestListener(_pageRequestListener!);
    _pagingController.refresh();
  }
}
@FilledStacks
Copy link
Owner

@AsheKR we've never had this requirement so it's not built into Stacked at the moment. This came up a few times in different ways. For instance getting life cycle callbacks in the viewmodel.

I'll add this to the list of features but right now we have nothing to facilitate this.

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

No branches or pull requests

2 participants