I have observed that RouteParams get method is not actually always returning a string. I have an example project for reproduction available here: https://github.com/erikist/route-params-failure
/cc @leonsenft
There's a cast from Map<String, dynamic> to Map<String, String> here:
https://github.com/dart-lang/angular/blob/master/angular/lib/src/router/rules/rules.dart#L95
The issue appears to stem from the fact the link DSL used to navigate is specified as List<dynamic>. For example, for the route @Route('/foo/:id', name: 'Foo'), the link can be written as ['Foo', {'id': 12}]. Notice 12 is an integer literal, not a string. I'm guessing this integer is then propagated all the way until the aforementioned cast.
Enforcing the DSL to be specified exclusively with strings would be cumbersome and a huge breaking change, so I suggest we just convert integer parameters to strings upon reading the navigation link.
so I suggest we just convert integer parameters to strings upon reading the navigation link
Sounds like JS-like "magic" to me.
I think it would be better to throw an error that only strings are allowed.
This would also cover other cases where not a literal but a reference is used that points to non-String and non-integer values.
I've run into this issue internally, though at the time I thought it was me >.>
I think updating the link DSL would be a breaking change, right? If that takes too much time I think it would be much better for the framework to just call toString so that the API isn't actively lying to users.
I concur! I am an idiot and more apt to trust the static analyzer more than myself. I'd also say a combover would also be okay of just changing the return type to dynamic so I don't lose faith in my tools. :-D
Converting everything just to a string would work for me as well, the result for toString() of all kinds of references would also reveal what went wrong.
But now as Dart heading to strong mode, I'd prefer a fail fast strategy that points out errors instead of hiding them to hit me at unexpected times.
Obsolete; this was the old router which is no longer supported.
Most helpful comment
Converting everything just to a string would work for me as well, the result for
toString()of all kinds of references would also reveal what went wrong.But now as Dart heading to strong mode, I'd prefer a fail fast strategy that points out errors instead of hiding them to hit me at unexpected times.