Normally I can go()
to a route, and specify extra
to pass an object: void go(String location, {Object? extra})
. How can I pass the extra
parameter from the GoRoute's redirect
?
GoRoute(
path: '/',
redirect: (context, state) async {
final theObject = tryToGetTheObject();
if (theObject != null) {
// context.go("/location", extra: theObject); -> throws error
// return state.namedLocation("Location", extra: theObject); -> doesn't exist
return state.namedLocation("Location"); // doesn't allow extra
}
return null;
},
),
Alternatively, how can I load the object in the builder, since the (page)Builder may not be async (even though redirect is allowed to be):
GoRoute(
path: '/',
redirect: (context, state) async {
final theObject = tryToGetTheObject();
if (theObject != null) {
return state.namedLocation("Location");
}
return null;
},
),
GoRoute(
name: 'Location',
path: '/location',
builder: (context, state) async { // async not allowed
final theObject = state.extra ?? await tryToGetTheObject(); // async not allowed
if (theObject == null) throw Exception("Invalid state");
return LocationWidget(theObject);
},
),