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

Other ways of specifying the page to go to #346

Closed
gazialankus opened this issue Dec 9, 2024 · 2 comments
Closed

Other ways of specifying the page to go to #346

gazialankus opened this issue Dec 9, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@gazialankus
Copy link
Contributor

When navigating between pages in pageListBuilder, it gets tricky to address which one you want to navigate to. Indices or next/prev is not reliable as they tend to shift over time. showPageWithId is best but you have to give ids to each page. It would be nice to have a convenient way to address which one of the pages you want to navigate to.

Since id is an object, I actually give the type as the id and found that it works very well. For example, when I do this,

class UserDetailViewPage extends SliverWoltModalSheetPage {
  UserDetailViewPage(BuildContext context, User user)
      : super(
    id: UserDetailViewPage,
    mainContentSliversBuilder: (context) =>

I'm able to do this later

WoltModalSheet.of(context).showPageWithId(UserDetailViewPage);

However, if I ever want to use two UserDetailViewPage instances I would have to use another solution.

So what I think we can do is to give a discriminator/selector function that will decide which specific page we should go to. Something like:

// there is a single user detail page to find 
// find it by type
WoltModalSheet.of(context).showPageOfType<UserDetailViewPage>();
// find it with a general selector function
WoltModalSheet.of(context).showPage(with: (p) => p is UserDetailViewPage);

// there can be multiple user detail pages but I want to show the one with selectedUserId
// the general selector function can help
WoltModalSheet.of(context).showPage(with: (p) => p is UserDetailViewPage && p.userId == selectedUserId);
// or maybe better with strong types
WoltModalSheet.of(context).showPage<UserDetailViewPage>(with: (p) => p.userId == selectedUserId);

This way we can specify at the time of navigation which one of those instances we want to navigate to. How does this sound?

@gazialankus gazialankus added the enhancement New feature or request label Dec 9, 2024
@ulusoyca
Copy link
Collaborator

ulusoyca commented Dec 9, 2024

@gazialankus this is amazing suggestion. Do you think you can create a PR? It should be straigh-forward. You can also update the example project with your suggestion in this file.

WoltModalSheet.of(context).showPage<UserDetailViewPage>(with: (p) => p.userId == selectedUserId);

We should also handle the case where the the condition is not met for example returning true or false as in

  bool showAtIndex(int index) {
    if (index < _pages.length && index >= 0) {
      _currentPageIndex = index;
      return true;
    }
    return false; // No navigation occurred, already at the last page.
  }

@ulusoyca ulusoyca self-assigned this Dec 9, 2024
@ulusoyca
Copy link
Collaborator

Merged. Thanks for the contribution. Target release: 0.10.0

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

2 participants