I have a dynamic x and I would like to assign x to T s if x is T, and otherwise assign null to s. S
dynamic x
x
T s
x is T
null
s
Dart 2 has generic functions which allows
T cast(x) => x is T ? x : null;
dynamic x = something(); String s = cast(x);
you can also use
var /* or final */ s = cast(x);
and get String inferred for s
String