Below is the code where I am first printing the type of myVar. It returns List<dynamic> in the console. But when I compare its type in a if condition, it does not pass this condition.
print(myVar.runtimeType);
if (myVar.runtimeType is List<dynamic>) {
print("Yes");
}
Run Code Online (Sandbox Code Playgroud)
What's wrong here?
ali*_*tor 14
runtimeType is of type Type and never going to be List or int.
The is operator automatically compares types.
Also when writing a type, if you leave the generic parameter empty, it will be read as a dynamic. for example List and List<dynamic> have the same type.
if (myVar is List) {
print("Yes");
}
Run Code Online (Sandbox Code Playgroud)