Skip to main content
The 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: Null is a subtype of all nullable types (e.g., String?, int?, Object?).
  • Disjoint Types: Null is not a subtype of Object or 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 both Object (non-nullable) and Null.

Syntax and Instantiation

The Null class cannot be instantiated via a generative constructor. The only way to obtain an instance of this type is via the null literal.
// Explicitly typing a variable as Null
Null emptyValue = null;

// The following results in a compile-time error:
// The class 'Null' doesn't have an unnamed constructor.
// Null invalid = Null(); 

Nullable Types as Unions

Syntactically, a nullable type T? is conceptually a union of the type T and the type Null.
int? nullableInteger;

// This variable can hold an int OR the instance 'null'
nullableInteger = 10;   // Valid: Type is int
nullableInteger = null; // Valid: Type is Null

Runtime Characteristics and Members

At runtime, the null 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 (?.).
void main() {
  Null val = null;
  
  // Type checking
  print(val is Null);    // true
  print(val is Object);  // false (Object is non-nullable)
  print(val is Object?); // true
  
  // Direct member invocation
  // This is valid because Null overrides these methods
  print(val.toString()); // "null"
  print(val.hashCode);   // 0
}

Never Type Interaction

The Null 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