Native<T> class final

Annotation specifying how to bind an external function to native code.

The annotation applies only to external function declarations.

A Native-annotated external function is implemented by native code. The implementation is found in the native library denoted by assetId.

The compiler and/or runtime provides a binding from assetId to native library, which depends on the target platform. The compiler/runtime can then resolve/lookup symbols (identifiers) against the native library, to find a native function, and bind an external Dart function declaration to that native function.

Use this annotation on external functions to specify that they are resolved against an asset, and to, optionally, provide overrides of the default symbol and asset IDs.

The type argument to the Native annotation must be a function type representing the native function's parameter and return types.

Example:

@Native<Int64 Function(Int64, Int64)>()
external int sum(int a, int b);

Calling such function will try to resolve the symbol in (in that order)

  1. the provided or default assetId,
  2. the native resolver set with Dart_SetFfiNativeResolver in dart_api.h, and
  3. the current process.

At least one of those three must provide a binding for the symbol, otherwise the method call fails.

NOTE: This is an experimental feature and may change in the future.

Annotations
  • @Since('2.19')

Constructors

Native({String? assetId, bool isLeaf = false, String? symbol})
const

Properties

assetId String?
The ID of the asset in which symbol is resolved, if not using the default.
final
hashCode int
The hash code for this object.
no setterinherited
isLeaf bool
Whether the function is a leaf function.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
symbol String?
The native symbol to be resolved, if not using the default.
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited