missing_ annotation_ on_ struct_ field
Fields of type '{0}' in a subclass of '{1}' must have an annotation indicating the native type.
Description
#
The analyzer produces this diagnostic when a field in a subclass of
Struct
or
Union
whose type requires an annotation doesn't have one.
The Dart types
int
,
double
, and
Array
are used to represent multiple
C types, and the annotation specifies which of the compatible C types the
field represents.
For more information about FFI, see C interop using dart:ffi.
Example
#
The following code produces this diagnostic because the field
x
doesn't
have an annotation indicating the underlying width of the integer value:
import 'dart:ffi';
final class C extends Struct {
external int x;
}
Common fixes
#Add an appropriate annotation to the field:
import 'dart:ffi';
final class C extends Struct {
@Int64()
external int x;
}
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Page last updated on 2025-9-4. View source or report an issue.