What is the purpose of the double underscore, after a single underscore, as a parameter to a function / class method?

Issue

In my exploration of Polymer Dart 1.0.0, I’ve found for events, and observer methods, I am forced to use this pattern

@reflectable
void someEvent([_, __]) {
    ...
}

or on an observer method

@Observe('someField')
void someFieldChanged([_, __]) {
    ...
}

I understand what the square brackets are for, optional parameters, I also understand that if you don’t care about the passed parameters, you can represent this parameter with the underscore. What surprised me was the examples I looked at used double underscore, __, as the second symbol between the square brackets. When I tried to use just a single underscore again, I get a duplicate formal parameter error. Is there some reason why the second parameter you don’t care about has to be different from the first? By this logic, if I include a third one, does it mean it’ll have to be a triple underscore ___?

Thanks.

Solution

Nothing special. _ as __ as a are just variable identifiers. _ is often used to name an unused variable.
Here there are 2 variables unused, the first one is named _ and the second one __.
With multiple unused variables it’s common to name them _, __, ___ … or _1,_2,_3

Answered By – Alexandre Ardhuin

Answer Checked By – Candace Johnson (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published.