Dart : How to Check if a variable type is String

Instead of

if(T is String)

it should be

if(_val is String)

The is operator is used as a type-guard at run-time which operates on identifiers (variables). In these cases, compilers, for the most part, will tell you something along the lines of T refers to a type but is being used as a value.

Note that because you have a type-guard (i.e. if(_val is String)) the compiler already knows that the type of _val could only ever be String inside your if-block.

Should you need to explicit casting you can have a look at the as operator in Dart, https://www.dartlang.org/guides/language/language-tour#type-test-operators.

Leave a Comment

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