Skip to main content
A super-initializer parameter (often referred to as a super parameter) is a syntactic feature in Dart that allows a subclass constructor to forward arguments directly to a superclass constructor without explicitly passing them through the initializer list. By applying the super. prefix to a parameter in the subclass constructor signature, the Dart compiler automatically binds and routes that argument to the corresponding parameter in the superclass.

Syntax Comparison

Prior to the introduction of super initializers, forwarding parameters required declaring the parameter in the subclass and explicitly passing it via the initializer list:
Using a super initializer, the parameter is forwarded inline directly from the constructor signature:

Parameter Resolution Mechanics

The compiler resolves super. parameters differently depending on whether they are positional or named. 1. Positional Parameters When super. is applied to positional parameters, the Dart compiler maps them to the superclass constructor’s positional parameters based strictly on their declaration order.
2. Named Parameters When super. is applied to named parameters, the compiler maps them to the superclass constructor’s named parameters by matching the exact identifier. Declaration order is irrelevant.

Technical Constraints and Behavior

  • Type Inference: The type of a super. parameter is implicitly inferred from the corresponding parameter in the superclass constructor. Explicitly declaring the type (e.g., int super.id) is redundant unless you are intentionally restricting the parameter to a stricter subtype.
  • Interaction with Explicit Super Invocations: Super parameters can be combined with an explicit super constructor call (e.g., : super.named(...)) in the initializer list, but strict rules apply to prevent argument duplication or ambiguity:
    • Positional Parameters: If a constructor uses positional super parameters, the explicit super constructor invocation cannot contain any positional arguments. It is a compile-time error to mix positional super parameters with explicitly passed positional arguments in the super(...) call.
    • Named Parameters: Named super parameters can be used alongside an explicit super call, provided the explicit call only provides other named arguments. You cannot pass a named argument in the super(...) call if a super. parameter is already forwarding it.
Tired of Poor Dart Skills? Fix That With Deep Grasping!Learn More