Dollar sign can be observed in generated classes very often.
Also types start there with $
sign. I know Dart language allows class names to contain dollar sign but maybe there is a hidden meaning of it which I am not aware of? I found similar question on stackoverflow but it was asked in 2012 and the answer is not valid any more.
Example 1.
class Counter {
int _counter = 0;
int next() => ++_counter;
}
class Operation {
void operate(int step) { doSomething(); }
}
class $OperationWithCounter = Operation with Counter;
class Foo extends $OperationWithCounter{
void operate([int step]) {
super.operate(step ?? super.next());
}
Variable names should not start with underscore _ or dollar sign $ characters, even though both are allowed.
Since you want the interpolation for "$dollars", you can't use "$" literally, so you need to escape it: int dollars = 42; print("I have \$$dollars."); If you don't want to use an escape, you can combine the string from raw and interpreted parts: int dollars = 42; print(r"I have $" "$dollars.");
\$ is the correct escape sequence for a dollar sign. If you don't need interpolation in your string you can also use a raw string literal by prefixing with r.
By convention generated code starts with “_$”, to mark it as private and generated. So the generated implementation will be called “_$User”. To allow it to extend “User” there will be a private constructor for this purpose called “_”: === user.dart ===abstract class User {
Dart identifiers can contain $
. It's just another letter to the language, but it is traditionally reserved for generated code. That allows code generators to (largely) avoid having to worry about naming conflicts as long as they put a $
somewhere in the names they create.
In this particular case, the name is simply intended to represent a synthetic name that did not occur in the original program. It was "generated" by the desugaring described where you found it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With