field_in_struct_with_initializer
Details about the 'field_in_struct_with_initializer' diagnostic produced by the Dart analyzer.
Fields in subclasses of 'Struct' and 'Union' can't have initializers.
Description
#
The analyzer produces this diagnostic when a field in a subclass of
Struct has an initializer.
For more information about FFI, see C interop using dart:ffi.
Example
#
The following code produces this diagnostic because the field p has an
initializer:
dart
// @dart = 2.9
import 'dart:ffi';
final class C extends Struct {
Pointer p = nullptr;
}
Common fixes
#Remove the initializer:
dart
// @dart = 2.9
import 'dart:ffi';
final class C extends Struct {
Pointer p;
}
Was this page's content helpful?
除非另有说明,文档之所提及适用于 Dart 3.10.3 版本报告页面问题.