Description
This code:
class A {
final String a;
final String b;
}
produces diagnostics for field_not_initialized
and has a convenient fix to add a constructor:
If I use that fix and later add a new field c
:
class A {
final String a;
final String b;
final String c;
A({required this.a, required this.b});
}
There is no diagnostic on c
, nor are there any code actions to add C to the constructor (from the declaration of c
, where I was typing). Instead, there is a fix on the constructor:
This is less convenient because it requires moving to the constructor and there's no option to add it as a named field (you have to use "Add final field formal parameters" and then "Convert selected formal parameter(s) to named" or "Convert all formal parameters to name" (although that one doesn't move it to the end where you might prefer it)).
It would be useful if a field that is not assigned in a constructor (causing final_not_initialized_constructor
) provided a fix/assist at the location of the field (with both named and positional options).
(@bwilkerson one thing I thought about here was having context messages on final_not_initialized_constructor
that point at the field, and showing fixes against the locations of context messages in addition to where the diagnostic is rendered... although it may fall down when there are two constructors with this diagnostic pointing at the same field as that would result in two fixes on the field declaration)