Search code examples
flutterdartroutesnavigationflutter-go-router

Go_router current route queryParams


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)


Solution

  • 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"}),