I'd like to handle urls like /?query=xxx
, and redirect to the url /query/
with the query content being passed as extra
// Where should this code go ?
if (state.queryParams["code"] != null) {
context.goNamed('query', extra: state.queryParams["query"]);
}
...
GoRoute(
name: 'query',
path: '/query',
builder: (context, state) => QueryScreen(query: state.extra.toString()),
),
When trying to add this conditional logic in another GoRoute's builder, the app breaks at runtime with error No GoRouter found in context
The redirect
key from GoRouter expects to return a string, so it doesn't appear possible to specify extra variables to pass to the screen widget.
Is there a simpler/better solution than having to wrap my StatelessWidget in a StatefulWidget wrapper that'll execute the context.go
in its initState method ?
Edit: Actually, the initState doesn't have access to GoRouter and Navigator in its context, and trying to delay the execution of the redirection with Timer or SchedulerBinding didn't change anything.