Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

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:
class Base {
  final int id;
  Base(this.id);
}

// Legacy approach
class Derived extends Base {
  final String name;
  
  Derived(int id, this.name) : super(id); 
}
Using a super initializer, the parameter is forwarded inline directly from the constructor signature:
// Modern approach using super parameters
class Derived extends Base {
  final String name;
  
  Derived(super.id, this.name); 
}

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.
class Point2D {
  final double x;
  final double y;
  Point2D(this.x, this.y);
}

class Point3D extends Point2D {
  final double z;
  
  // super.x maps to the first positional parameter (x)
  // super.y maps to the second positional parameter (y)
  Point3D(super.x, super.y, this.z); 
}
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.
class Configuration {
  final bool isDebug;
  final String environment;
  
  Configuration({required this.isDebug, this.environment = 'prod'});
}

class AppConfig extends Configuration {
  final int port;
  
  // Maps directly to 'isDebug' and 'environment' in the superclass
  AppConfig({
    required this.port,
    required super.isDebug,
    super.environment,
  });
}

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.
class Base {
  final int x;
  final int y;
  final String label;
  
  Base.custom(this.x, this.y, {required this.label});
}

class Derived extends Base {
  // Valid: Positional super parameters map to x and y.
  // The explicit super call provides the named argument 'label'.
  // No positional arguments are passed in super.custom(...).
  Derived(super.x, super.y) : super.custom(label: 'Default'); 
}
Master Dart with Deep Grasping Methodology!Learn More