In Dart, you can use wildcard names(names consisting on underscores only: _
, __
, ___
, … ). Usually it
should be used to name the variable/parameter that won’t be directly used but needs to be declared. For example, as counter in the for-loop:
for (var _ in [1, 2, 3]) doSomething();
or as a field, in the pattern:
void sayHello(Person p) {
switch (p) {
case (name, _):
print('Hello, $name!');
}
}
Currently, this is possible to read such wildcard variables, for example, print(_);
. However, such behavior is supposed to change in
the next versions of the Dart language, making such variables non-binding and breaking the code, where such variables are used. To avoid problems
during upgrades, it’s recommended to refactor the code, to not use wildcard variables.
What is the potential impact?
Once the breaking change is introduced, you will need to update all the code using wildcard variables or parameters to be able to upgrade to the
latest Dart language versions.