You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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) =>
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?
The text was updated successfully, but these errors were encountered:
@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.
We should also handle the case where the the condition is not met for example returning true or false as in
boolshowAtIndex(int index) {
if (index < _pages.length && index >=0) {
_currentPageIndex = index;
returntrue;
}
returnfalse; // No navigation occurred, already at the last page.
}
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,
I'm able to do this later
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:
This way we can specify at the time of navigation which one of those instances we want to navigate to. How does this sound?
The text was updated successfully, but these errors were encountered: