const_instance_field
Details about the 'const_instance_field' diagnostic produced by the Dart analyzer.
Only static fields can be declared as const.
Description
#The analyzer produces this diagnostic when an instance field is marked as being const.
Example
#
The following code produces this diagnostic because f is an instance
field:
class C {
const int f = 3;
}
Common fixes
#
If the field needs to be an instance field, then remove the keyword
const, or replace it with final:
class C {
final int f = 3;
}
If the field really should be a const field, then make it a static field:
class C {
static const int f = 3;
}
除非另有说明,文档之所提及适用于 Dart 3.10.3 版本报告页面问题.