The name collision is not a problem in constructor initializer lists. The left-hand-side of each initialization may only be a member variable. From the Dart language specification:
Initializer Lists
An initializer list begins with a colon, and consists of a comma-separated
list of individual initializers.
[...]
An initializer of the form v = e is equivalent to an initializer of the form this.v = e, both forms are called instance variable initializers.
Meanwhile, the expression on the right-hand-side cannot access this
and therefore can never refer to a member variable. Therefore:
class Foo {
int x;
Foo(int x) : x = x;
}
has no ambiguity: the member variable x
is initialized from the x
parameter.
The name collision can be a problem in a constructor body, however:
class Foo {
int x;
Foo(int x) : x = x {
x *= 10; // This modifies the local `x` parameter.
}
}
In such cases, the constructor body must be careful to explicitly use this.x
if it needs to use the member variable, not the parameter of the same name.