Union class Null safety

The supertype of all FFI union types.

FFI union types should extend this class and declare fields corresponding to the underlying native union.

Field declarations in a Union subclass declaration are automatically given a setter and getter implementation which accesses the native union's field in memory.

All field declarations in a Union subclass declaration must either have type int or double and be annotated with a NativeType representing the native type, or must be of type Pointer. For example:

typedef union {
 int a;
 float b;
 void* c;
} my_union;
class MyUnion extends Union {
  external int a;

  external double b;

  external Pointer<Void> c;

All field declarations in a Union subclass declaration must be marked external. You cannot create instances of the class, only have it point to existing native memory, so there is no memory in which to store non-native fields. External fields also cannot be initialized by constructors since no Dart object is being created.

Instances of a subclass of Union have reference semantics and are backed by native memory. The may allocated via allocation or loaded from a Pointer, but cannot be created by a generative constructor.

  • @Since('2.14')


Construct a reference to the nullptr.


hashCode int
The hash code for this object.
runtimeType Type
A representation of the runtime type of the object.


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


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