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

Using customRouteBuilder leads to the Page not being rebuild when Query Path Params change #1857

Open
felixwoestmann opened this issue Feb 8, 2024 · 2 comments

Comments

@felixwoestmann
Copy link

Hello,
in our project we ran into an issue.

Plattform: Web
What we want to achieve:
We want to wrap every single route with a SelectionArea to provide the ability to copy text easily for the user. To do that we tried to create a new Route class, wrapping every Page.

class OurRouteClass extends CustomRoute {
  OurRouteClass({
    required super.page,
    super.barrierDismissible,
    super.path,
  }) : super(
          customRouteBuilder: <T>(_, child, routePage) => PageRouteBuilder<T>(
            settings: routePage,
            pageBuilder: (_, __, ___) => SelectionArea(child: child),
            transitionsBuilder: TransitionsBuilders.fadeIn,
            opaque: false,
            barrierDismissible: barrierDismissible,
          ),
        );
}

This worked, but lead to an issue with pages using Query or Path Params.
When calling appRouter.replace() to update the current page with different QueryParams the UI is not updated. Specifically we can see the URL change, but the UI displays the old information. Debugging into the PageRouteBuilder we can observe that the old Parameters are provided still.

@RoutePage()
class ProductsScreen extends StatelessWidget {
  const ProductsScreen({
    @PathParam() required this.hubId,
    @QueryParam() this.page,
    @QueryParam() this.availability,
    @QueryParam() this.searchType,
    @QueryParam() this.searchTerm,
    this.pendingState,
    super.key,
  });

For now we fixed the issues using implements AutoRouteWrapper on all faulty routes, which solved the issue. It would be great however if we had a solution, introduced in a single place.

Doeas anybody know a solution? Am I using customRouteBuilder wrongly?

@felixwoestmann
Copy link
Author

This issue keeps persisting, we also noticed that the barrierDismissible option didn't work when using the customRouteBuilder.

We for now solved the issue of wrapping every route with a SelectionArea by defining a mixin.

mixin SelectionAreaWrapper on Widget implements AutoRouteWrapper {
  @override
  Widget wrappedRoute(BuildContext context) => SelectionArea(child: this);
}

@Milad-Akarie
Copy link
Owner

@felixwoestmann You'll need to create a page-based custom route for it to work normally, you can find custom route implementations inside auto_route_page.dart.

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