redirect method
Function to handle redirection logic if any for this page
Implementation
@nonVirtual
Future<String?> redirect(
BuildContext context,
GoRouterState state,
) async {
if (super.key is GlobalKey) {
final GlobalKey key = super.key as GlobalKey;
if (key.currentState == null) {
// when bloc state changes go_router can call redirect
// multiple times. once before state is created and then
// after multiple times after state is created every time
// the widget is rebuilt. We handle redirect only on the
// first call to redirect before state is created.
final namedRoute = await evaluateRedirect(
context,
state,
);
if (namedRoute != null) {
logging.Logger(
runtimeType.toString(),
).fine(
'Redirecting to named route: $namedRoute',
);
goTo(namedRoute);
}
}
}
return null;
}