I'm encountering an issue with accessing queryParams
in my Flutter app while using the GoRouter package for routing. It seems that a recent update has caused a change in how queryParams
can be accessed from a route at the point of definition. Here's a snippet of my code:
final _router = GoRouter(
routes: [
GoRoute(
path: OnBoardingScreen.route(),
name: OnBoardingScreen.route(),
builder: (context, state) {
return OnBoardingScreen(
next: state.queryParameters['next'],
);
},
),
],
);
Previously, I could access queryParams
directly from the state. However, after the recent update, queryParams
seems to be inaccessible from the state.
I would greatly appreciate any insights or suggestions on how to address this issue. Thank you in advance for your help!
The update 10.0.0 introduced some breaking changes, one of them is the removal of queryParameters
getter from GoRouterState
.
BREAKING CHANGE:
- Replaces location, queryParameters, and queryParametersAll in GoRouterState with Uri.
- See Migrating to 10.0.0 or run
dart fix --apply
to fix the breakages.
The full URI of the route is in the uri
property of the state, which includes the query parameters. You can access it with the queryParameters
getter of the Uri
class like this:
state.uri.queryParameters['next']