Dart Analyze logoDart Analyze/
DRT-W1469

Missing annotation for fields in subclasses of `Struct` or `Union`DRT-W1469

Major severityMajor
Bug Risk categoryBug Risk

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;
}