Open
Description
I find dart constructors initializer list often hinder readability and needlessly redundant when trying to have private members. They are also sometimes annoying to read in public api scenarios
I would like the ability to populate private members with named parameters without resorting to an initializer list.
What I propose is to have those 2 snippets be equivalent:
Currently:
class House {
final int _windows;
final int _bedrooms;
final int _swimmingPools;
House.named({
required int windows,
required int bedrooms,
required int swimmingPools,
}) : _windows = windows,
_bedrooms = bedrooms,
_swimmingPools = swimmingPools
;}
Suggared:
class House {
final int _windows;
final int _bedrooms;
final int _swimmingPools;
House.named({
required this._windows,
required this._bedrooms,
required this._swimmingPools,
});
}
In both cases you'd call House.named(windows: 2, bedrooms: 1, swimmingPools: 4);
. The first snippet has needless noise in it.
I'm sure this was a design decision but I can't find an issue other than the closed one I posted above about this.