Using go_router :
GoRouter.of(context).location
gives us the current route path such as /product/10110
but I'd like to know how to also get the current route queryParams in a similar fashion
(outside of the GoRoute builder)
Using go_router :
GoRouter.of(context).location
gives us the current route path such as /product/10110
but I'd like to know how to also get the current route queryParams in a similar fashion
(outside of the GoRoute builder)
You can now have this functionality.
class SampleWidget extends StatelessWidget {
SampleWidget({super.key});
@override
Widget build(BuildContext context) {
Map<String,dynamic> qparams = GoRouterState.of(context).uri.queryParams;
return const Scaffold(
body: ...
);
}
}
This way you can directly access the query params you send using go_router, like:
context.goNamed("page", queryParams: {"name": "Addy", "age": "22"}),
go_router
has it's qweryParams
in its state.Hence pass the state
to the page
GoRoute(
name: "test",
path: "/test",
builder: (context, state) {
return SampleWidget(
goRouterState: state, π Pass state here
);
},
),
context.goNamed("test", queryParams: {"email": "[email protected]", "age": "25"}),
class SampleWidget extends StatelessWidget {
GoRouterState? goRouterState;
SampleWidget({super.key, this.goRouterState});
@override
Widget build(BuildContext context) {
print(goRouterState?.queryParams.toString()); π access anywhere like so
return const Scaffold(
body: ...
);
}
}
© 2022 - 2024 β McMap. All rights reserved.