Null class represents the absence of a value within the Dart type system. It is a special type that contains exactly one instance: the reserved literal null.
Type Hierarchy Position
In Dart’s sound null safety system,Null serves as a distinct type at the bottom of the nullable type hierarchy.
- Subtype Relationships:
Nullis a subtype of all nullable types (e.g.,String?,int?,Object?). - Disjoint Types:
Nullis not a subtype ofObjector any non-nullable type. It exists in a separate branch of the type tree from non-nullable types. - Root: The root of the entire Dart type system is
Object?(nullable Object), which is the supertype of bothObject(non-nullable) andNull.
Syntax and Instantiation
TheNull class cannot be instantiated via a generative constructor. The only way to obtain an instance of this type is via the null literal.
Nullable Types as Unions
Syntactically, a nullable typeT? is conceptually a union of the type T and the type Null.
Runtime Characteristics and Members
At runtime, thenull literal is an object. The Null class explicitly defines specific members, such as toString and hashCode. Because these members are defined on the Null class itself, they can be invoked directly on a value of type Null without triggering a NoSuchMethodError or requiring a null-aware operator (?.).
Never Type Interaction
TheNull type is the supertype of Never. While Never indicates that an expression cannot complete successfully (e.g., a function that always throws), Null indicates that an expression completes successfully with the specific value null.
Master Dart with Deep Grasping Methodology!Learn More





