You can use the keyword is
or switch over runtimeType
:
dynamic foo = 42;
if (foo is int) {
print("Hello");
}
switch (foo.runtimeType) {
case int: {
print("World");
}
}
Consider using is
instead of directly using runtimeType
. As is
works with subclasses. While using runtimeType
is a strict comparison.