Skip to main content
The is operator is a runtime type test operator that evaluates whether an object is an instance of a specified type or its subtype. It returns a boolean true if the object’s runtime type matches the specified type hierarchy, and false otherwise. Dart also provides the is! operator, which is the exact logical negation of is, returning true if the object is not an instance of the specified type.

Syntax

Core Mechanics

1. Subtype Resolution The is operator respects Dart’s object-oriented inheritance and interface implementations. If a class Child extends or implements Parent, evaluating a Child instance against the Parent type yields true.
2. Type Promotion via Flow Analysis When the is operator is used in a conditional statement (like if or switch), the Dart analyzer performs control flow analysis. If the test evaluates to true, the compiler automatically promotes the variable from its declared type to the tested type within the scope of that execution branch. This promotion only applies to local variables and parameters, not to instance variables or getters, as their values could change asynchronously.
3. Nullability Handling The is operator strictly evaluates against Dart’s sound null safety system. Testing a null value against a non-nullable type evaluates to false. Testing a null value against a nullable type (denoted by ?) evaluates to true.
4. Generic Type Reification Because Dart uses reified generics, the is operator can evaluate the specific type arguments of generic collections at runtime, unlike languages that use type erasure.
Tired of Poor Dart Skills? Fix That With Deep Grasping!Learn More