Can't cast `RouteMatch` to its proper Type in `AutoRedirectGuard`
hasanmhallak opened this issue · comments
Hasan M. Hallak commented
example:
class LanguageRouteGuard extends AutoRedirectGuard {
final LanguageNotifier _languageNotifier;
LanguageRouteGuard(this._languageNotifier);
@override
Future<bool> canNavigate(RouteMatch route) async {
return true;
}
@override
void onNavigation(NavigationResolver resolver, StackRouter router) {
// here.
final routeMatch = resolver.route as RouteMatch<ChooseLanguageRouteArgs>
if (routeMatch.args != null && routeMatch.args.skipRouteGuard) return resolver.next(true);
if (_languageNotifier.isLanguageSelected()) {
resolver.next(false);
router.push(MainRoute());
} else {
resolver.next(true);
}
}
}
this will throw: Unhandled Exception: type RouteMatch<\dynamic>
is not a subtype of type RouteMatch<\ChooseLanguageRouteArgs>
in type cast.
but if I remove the casting I can access the ChooseLanguageRouteArgs
but without a type safty.
Milad Akarie commented
@hasanmhallak it's not save to cast the routeMatch like this, why don't cast only the args instead?
Hasan M. Hallak commented
@Milad-Akarie silly me, I was so concentrated I didn't even thought if this.
thank you, I'm closing this now.