invalid_field_type_in_struct
Fields in struct classes can't have the type '{0}'. They can only be declared as 'int', 'double', 'Array', 'Pointer', or subtype of 'Struct' or 'Union'.
Description
#The analyzer produces this diagnostic when a field in a subclass of Struct
has a type other than int
, double
, Array
, Pointer
, or subtype of Struct
or Union
.
For more information about FFI, see C interop using dart:ffi.
Example
#The following code produces this diagnostic because the field str
has the type String
, which isn't one of the allowed types for fields in a subclass of Struct
:
import 'dart:ffi';
final class C extends Struct {
external String s;
@Int32()
external int i;
}
Common fixes
#Use one of the allowed types for the field:
import 'dart:ffi';
import 'package:ffi/ffi.dart';
final class C extends Struct {
external Pointer<Utf8> s;
@Int32()
external int i;
}
Unless stated otherwise, the documentation on this site reflects Dart 3.7.3. Page last updated on 2025-05-08. View source or report an issue.