Milad-Akarie / auto_route_library

Flutter route generator
MIT License
1.5k stars 375 forks source link

Explicit Type Casting for Route Assignments #1929

Open naveeez10 opened 1 month ago

naveeez10 commented 1 month ago

Lets say i have a condition to route to RouteA if a boolean value loggedIn is true, otherwise we want to route to RouteB.

I need to define it as :

final PageRouteInfo route = loggedIn ? RouteA() : RouteB();

But this doesn't work. We need to explicitly typecase it as follows.

final PageRouteInfo route = (loggedIn ? RouteA() : RouteB()) as PageRouteInfo;

I think this should be handled and there shouldn't be a need for explicit typecast

Milad-Akarie commented 1 month ago

@naveeez10 This should work just fine final PageRouteInfo route = loggedIn ? RouteA() : RouteB(); This's dart specification, not related to auto_route, any sub-type can be assigned to it's parent