Skip to main content
An external method in Dart is a method declaration that defers its implementation to an external source, such as the Dart runtime, a native library, or the host environment (like JavaScript). It instructs the Dart compiler to accept the method signature for type-checking and static analysis, with the understanding that the actual execution logic will be dynamically or statically linked from outside the current Dart codebase. Syntactically, the external keyword is placed at the beginning of the method declaration. Because the implementation is handled elsewhere, the method body is omitted entirely and replaced with a terminating semicolon.
// External top-level function
external void performNativeOperation(int pointer);

class SystemInterface {
  // External instance method
  external String getSystemVersion();

  // External getter
  external int get memoryCapacity;

  // External setter
  external set memoryCapacity(int value);
}
The external modifier can also be applied to constructors, including factory constructors. This is standard in platform-specific SDK implementations where the instantiation logic is handled by the underlying engine rather than Dart code.
class HostBuffer {
  // External generative constructor
  external HostBuffer(int size);

  // External factory constructor
  external factory HostBuffer.allocate(int size);
}

Technical Characteristics

  • Syntax Enforcement: An external method cannot have a block body ({ ... }) or an arrow body (=> ...). Attempting to provide a body will result in a compile-time syntax error.
  • Runtime Binding: The resolution of the external method to its actual implementation is platform-dependent. If the Dart runtime or compiler fails to locate and bind the corresponding external implementation, invoking the method at runtime results in a NoSuchMethodError.
  • SDK Patching: Within the Dart SDK architecture, external methods are frequently used in conjunction with the @patch annotation. The core library defines the external signature, and platform-specific compilers (such as the Dart VM or dart2js) inject the patched implementation during the compilation phase.
Tired of Poor Dart Skills? Fix That With Deep Grasping!Learn More