Skip to main content
A default constructor is an implicit, unnamed, zero-argument constructor automatically generated by the Dart compiler for any class that does not declare an explicit constructor.

Mechanism and Behavior

When a class definition omits all constructor declarations, the compiler injects a constructor equivalent to the following signature and initializer list:
ClassName() : super();
This implicit constructor performs a single specific action: it invokes the unnamed, no-argument constructor of the superclass. Note: The initialization of instance variables (via inline assignments or default null values) occurs during the object allocation phase, strictly before the default constructor is invoked. The default constructor itself does not contain logic for field initialization.

Syntax Visualization

In the following example, the class Point does not define a constructor. Consequently, Dart provides the default constructor, allowing instantiation via Point().
class Point {
  double x = 0;
  double y = 0;
  // No constructor defined here.
}

void main() {
  // The default constructor is invoked.
  var p = Point(); 
}

Suppression of Default Constructor

The default constructor is only available if the class contains no constructor declarations whatsoever. If a developer defines any constructor—whether named, unnamed, or factory—the compiler ceases to generate the default constructor. If a parameterless constructor is required after defining a parameterized one, it must be explicitly defined.
class Vector {
  double x;
  
  // The presence of this constructor suppresses the default constructor.
  Vector(this.x); 
}

void main() {
  var v1 = Vector(10); // Valid
  
  // var v2 = Vector(); // Compile-time Error: The default constructor no longer exists.
}

Inheritance Constraints

Constructors are not inherited in Dart. A subclass does not inherit the default constructor of its superclass; rather, it generates its own if no other constructors are defined. Because the generated default constructor implicitly executes : super(), the immediate superclass must possess an accessible, unnamed, no-argument constructor. A compile-time error occurs if the superclass:
  1. Has no unnamed constructor (e.g., only defines named constructors like Class.named()).
  2. Has an unnamed constructor that requires arguments.
If the superclass lacks a compatible unnamed, no-argument constructor, the subclass cannot rely on the default constructor and must explicitly define a constructor that invokes an available superclass constructor.
Master Dart with Deep Grasping Methodology!Learn More