class a {/*code*/}
class b extends a {/*more code*/}
void main() {
b c = new b();
print(c.runtimeType == a); //type == inheritedType
//or
print(c.runtimeType inherits a); //operator for inheritance
//or
print(c inherits a); //other operator for inheritance
}
Can you use type == inheriting type
, type inherits other type
, or instance inherits other type or type
?
Is there even a way to do such thing?
Because I have not found any way yet.
To achieve the same result in Dart, we can use the type test operator is . It returns true if the object has the specified type.
The runtimeType property helps to find what kind of data is stored in the variable using var keyword. In the next section, we'll explore usage of this property in for different type of data.
To check the type of a variable in Flutter and Dart, you can use the runtimeType property.
Use is
.
You can do c is a
. Notice that new a() is a
is true
as well. If you really want to know if an instance is a subtype of another type, you might ask c is a && c.runtimeType != a
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With