late_ final_ field_ with_ const_ constructor
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();
}
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Page last updated on 2025-9-1. View source or report an issue.