external_with_initializer
External fields can't have initializers.
External variables can't have initializers.
Description
#The analyzer produces this diagnostic when a field or variable marked with
the keyword external
has an initializer, or when an external field is
initialized in a constructor.
Examples
#The following code produces this diagnostic because the external field x
is assigned a value in an initializer:
dart
class C {
external int x;
C() : x = 0;
}
The following code produces this diagnostic because the external field x
has an initializer:
dart
class C {
external final int x = 0;
}
The following code produces this diagnostic because the external top level
variable x
has an initializer:
dart
external final int x = 0;
Common fixes
#Remove the initializer:
dart
class C {
external final int x;
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。