In Dart, syntactically nice way to cast dynamic to given type or return null?

Dart 2 has generic functions which allows

T? cast<T>(x) => x is T ? x : null;
dynamic x = something();
String s = cast<String>(x);

you can also use

var /* or final */ s = cast<String>(x);

and get String inferred for s

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)