missing_field_type_in_struct
Fields in struct classes must have an explicitly declared type of 'int', 'double' or 'Pointer'.
Description
#The analyzer produces this diagnostic when a field in a subclass of
Struct
or Union
doesn't have a type annotation. Every field must have
an explicit type, and the type must either be int
, double
, Pointer
,
or a subclass of either 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
doesn't have a type annotation:
dart
import 'dart:ffi';
final class C extends Struct {
external var str;
@Int32()
external int i;
}
Common fixes
#Explicitly specify the type of the field:
dart
import 'dart:ffi';
import 'package:ffi/ffi.dart';
final class C extends Struct {
external Pointer<Utf8> str;
@Int32()
external int i;
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。