Skip to main content
A super parameter is a syntactic feature in Dart that allows a subclass constructor to forward parameters directly to its superclass constructor without explicitly declaring the parameter and passing it through the initializer list. It is denoted by the super. prefix. When the Dart compiler encounters a super.identifier in a constructor’s parameter list, it automatically maps and forwards it to the invoked superclass constructor, eliminating boilerplate code.

Syntax Comparison

Prior to Dart 2.17, forwarding parameters required redundant declarations in both the constructor signature and the initializer list. Legacy Approach (Explicit Forwarding):
class BaseClass {
  final num x;
  final String y;

  BaseClass(this.x, {required this.y});
}

class SubClass extends BaseClass {
  final double z;

  // Verbose: 'x' and 'y' are declared, typed, and manually forwarded.
  SubClass(num x, this.z, {required String y}) : super(x, y: y);
}
Modern Approach (Super Parameters):
class BaseClass {
  final num x;
  final String y;

  BaseClass(this.x, {required this.y});
}

class SubClass extends BaseClass {
  final double z;

  // Concise: 'x' and 'y' are forwarded directly using 'super.'
  SubClass(super.x, this.z, {required super.y});
}

Technical Characteristics

1. Type Inference and Explicit Typing The type of a super parameter is implicitly inferred from the corresponding parameter in the superclass constructor. However, Dart fully allows explicit type annotations on super parameters. This is typically utilized when a subclass needs to restrict the parameter to a stricter subtype than what the superclass accepts.
class Base {
  final num value;
  Base(this.value);
}

class Sub extends Base {
  // Valid: Explicitly restricts 'value' to an int, which is a subtype of num.
  Sub(int super.value); 
}
2. Positional Parameter Resolution Positional super parameters are passed to the superclass constructor as positional arguments in the exact order they appear in the subclass constructor’s parameter list. They are mapped to the superclass constructor entirely by their position (index). The identifier used after super. in the subclass does not need to match the name of the corresponding positional parameter in the superclass.
class Point {
  final int x;
  final int y;
  Point(this.x, this.y);
}

class Point3D extends Point {
  final int z;
  
  // super.a maps to the first positional parameter 'x' in Point by index.
  // super.b maps to the second positional parameter 'y' in Point by index.
  // Only the sequence matters; the identifiers can be anything.
  Point3D(super.a, super.b, this.z); 
}
3. Named Parameter Resolution Unlike positional parameters, named super parameters are mapped strictly by their identifier. The order in which named super parameters are declared in the subclass does not matter, as the compiler matches the name directly to the superclass constructor’s named parameters. 4. Default Values Super parameters cannot declare default values. Attempting to assign a default value to a super parameter (e.g., super.value = 20) results in a compile-time error. A super parameter implicitly inherits the default value defined in the superclass. If a subclass must provide a different default value, it must declare a standard parameter and explicitly forward it to the superclass via the initializer list.
class Base {
  final int value;
  Base({this.value = 10});
}

class Sub extends Base {
  // INVALID: Super parameters cannot declare default values.
  // Sub({super.value = 20}); 

  // VALID: Use a regular parameter and explicit forwarding to override the default.
  Sub({int value = 20}) : super(value: value);
}
5. Initializer List Constraints The compiler enforces strict mutual exclusivity rules between super parameters and explicit super() invocations in the initializer list:
  • If a subclass constructor uses any positional super parameters, it is a compile-time error to include an explicit super(...) invocation that passes any positional arguments.
  • If a subclass constructor uses a named super parameter (e.g., super.y), it is a compile-time error to pass an argument for that specific named parameter in an explicit super(...) invocation.
Tired of Poor Dart Skills? Fix That With Deep Grasping!Learn More