Struct class abstract base

The supertype of all FFI struct types.

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

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

All field declarations in a Struct 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 struct {
 int a;
 float b;
 void* c;
} my_struct;
final class MyStruct extends Struct {
  @Int32()
  external int a;

  @Float()
  external double b;

  external Pointer<Void> c;
}

All field declarations in a Struct 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 Struct have reference semantics and are backed by native memory or typed data. They may allocated via allocation or loaded from a Pointer or created by ffi calls or callbacks. They cannot be created by a generative constructor.

Inheritance
Annotations
  • @Since('2.12')

Constructors

Struct()
Construct a reference to the nullptr.

Properties

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

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