late_ final_ field_ with_ const_ constructor
Details about the 'late_final_field_with_const_constructor' diagnostic produced by the Dart analyzer.
Can't have a late final field in a class with a generative const constructor.
Description
#
The analyzer produces this diagnostic when a class that has at
least one
const constructor also has a field marked both
late and final.
Example
#
The following code produces this diagnostic because the class
A has a const constructor and the
final field f is marked as
late:
class A {
late final int f;
const A();
}
Common fixes
#
If the field doesn't need to be marked late, then
remove the late
modifier from the field:
class A {
final int f = 0;
const A();
}
If the field must be marked late, then remove the
const modifier from the constructors:
class A {
late final int f;
A();
}
除非另有说明,文档之所提及适用于 Dart 3.12.2 版本报告页面问题.