> ## 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.

# Dart External Constructor

An external constructor in Dart is a constructor declaration that lacks an implementation body within the Dart source code. By using the `external` keyword, the constructor delegates its instantiation logic, memory allocation, and initialization to an external host environment, such as the Dart Virtual Machine (VM), a JavaScript engine, or native code via the Foreign Function Interface (FFI).

## Syntax

An external constructor is declared using the `external` modifier before the constructor name. It must be terminated with a semicolon rather than a block body.

```dart theme={"dark"}
class NativeBuffer {
  // Non-nullable fields must be initialized at declaration or marked external 
  // when using an external generative constructor.
  final int defaultCapacity = 256;
  external int size;

  // External generative constructor (initializing formals are prohibited)
  external NativeBuffer(int size);

  // External named constructor
  external NativeBuffer.allocate(int size);
  
  // External factory constructor
  external factory NativeBuffer.create();
}
```

## Technical Characteristics

* **Absence of Implementation:** An external constructor cannot have a block body (`{}`), an expression body (`=>`), or an initializer list (`: field = value`). The declaration acts strictly as a signature contract.
* **Parameter Restrictions:** The Dart language specification explicitly prohibits the use of initializing formals (`this.field`) and super-initializing formals (`super.field`) in external constructors. These constructs represent Dart-level initialization logic, which is strictly the responsibility of the external implementation.
* **Field Initialization Constraints:** Because external generative constructors cannot initialize fields (lacking both initializing formals and initializer lists), a class containing uninitialized `final` or non-nullable instance variables cannot use an external generative constructor. To satisfy Dart's sound null safety and definite assignment rules, you must use one of the following approaches:
  1. Use an `external factory` constructor instead of a generative constructor.
  2. Initialize the fields directly at their declaration point.
  3. Mark the fields themselves as `external` (a common pattern in JS interop and FFI).
* **Compiler Resolution:** The Dart compiler expects the implementation to be provided by the underlying runtime. If the runtime fails to link the external declaration to a native implementation, invoking the constructor results in a runtime `NoSuchMethodError`.
* **SDK Patching:** Within the Dart SDK, external constructors are frequently paired with the `@patch` annotation. The `external` keyword declares the API in the public-facing Dart interface, while a separate, platform-specific file provides the `@patch` implementation that interfaces directly with C++ or JavaScript.
* **Factory vs. Generative:** The `external` keyword can be applied to both generative constructors and factory constructors. When applied to a factory, the external environment is responsible for returning an instance that conforms to the class type, rather than just allocating memory for a new instance.

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Dart Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
