const_ with_ non_ const
Details about the 'const_with_non_const' diagnostic produced by the Dart analyzer.
The constructor being called isn't a const constructor.
Description
#
The analyzer produces this diagnostic when the keyword
const is used to invoke a constructor that isn't
marked with const.
Example
#
The following code produces this diagnostic because the
constructor in A
isn't a const constructor:
class A {
A();
}
A f() => const A();
Common fixes
#
If it's desirable and possible to make the class a constant
class (by making all of the fields of the class, including
inherited fields, final), then add the keyword
const to the constructor:
class A {
const A();
}
A f() => const A();
Otherwise, remove the keyword const:
class A {
A();
}
A f() => A();
除非另有说明,文档之所提及适用于 Dart 3.12.2 版本报告页面问题.