redirect_ to_ non_ const_ constructor
Details about the 'redirect_to_non_const_constructor' diagnostic produced by the Dart analyzer.
A constant redirecting constructor can't redirect to a non-constant constructor.
Description
#
The analyzer produces this diagnostic when a constructor
marked as const redirects to a constructor that
isn't marked as const.
Example
#
The following code produces this diagnostic because the
constructor C.a is marked as
const but redirects to the constructor
C.b, which isn't:
class C {
const C.a() : this.b();
C.b();
}
Common fixes
#
If the non-constant constructor can be marked as
const, then mark it as const:
class C {
const C.a() : this.b();
const C.b();
}
If the non-constant constructor can't be marked as
const, then either remove the redirect or remove
const from the redirecting constructor:
class C {
C.a() : this.b();
C.b();
}
除非另有说明,文档之所提及适用于 Dart 3.12.2 版本报告页面问题.