is operator is a type test operator that performs a runtime check to determine if an object conforms to a specific type. It evaluates to a boolean value, returning true if the object is an instance of the specified type or any of its subtypes.
Syntax
Evaluation Semantics
The expressionobj is T evaluates to true if the runtime type of obj is a subtype of T. In Dart’s nominal type system, this encompasses the following scenarios:
- Direct Instance:
objis an instance of the exact classT. - Subtype Polymorphism:
objis an instance of a class that extends, implements, or mixes inT. - Reified Generics: The runtime type arguments of
objsatisfy the constraints ofT(e.g.,List<int>is a subtype ofList<num>).
Nullability Rules
In null-safe Dart, the evaluation logic accounts for the nullability of the target typeT:
- Non-nullable Target: If
objevaluates tonullandTis non-nullable (e.g.,int), the expression evaluates tofalse. - Nullable Target: If
objevaluates tonullandTis nullable (e.g.,int?orNull), the expression evaluates totrue.
Type Promotion
Theis operator is integrated into Dart’s flow analysis. When the operator evaluates to true within a control flow structure, the compiler promotes the static type of the variable to the checked type within the guarded scope.
Type promotion occurs only when the compiler can guarantee type stability between the check and the usage. Eligible targets include:
- Local variables and parameters.
- Private final instance fields (since Dart 3.2), provided no conflicting getter exists in the class hierarchy.
The is! Operator
The is! operator serves as the logical negation of the is operator. The expression obj is! T is syntactic sugar for !(obj is T).
Master Dart with Deep Grasping Methodology!Learn More





