As a Separator and for Hierarchy
For example, it helps in distinguishing and organizing code in a clear hierarchy:
YourScreen
YourScreen$Form
_YourScreen$Form$Buttons
This notation is both convenient and understandable, allowing for quick selection of a name part with a double mouse click.
Additionally, for unions and sealed classes:
sealed class Base {}
base mixin M on Base {}
final class Base$A = Base with M;
final class Base$B = Base with M;
final class Base$C = Base with M;
final class Base$D = Base with M;
To Indicate Auxiliary or Private Use
When used at the beginning of a name, it signifies that the variable is auxiliary and typically not meant for public use. Moreover, unless marked private, it tends to be less prominent in IDE tooltips:
$someVar
_$someVar
For instance, I frequently use such variables for caching:
T? _$a;
T get a => _$a ??= _init();
Future<T>? _$fn;
Future<T> fn() => _$fn ??= Future(() {});
AsyncCache<T> _$cache;
This approach is also handy for using functions with conditional imports, especially when needing to differentiate imports by VM and JS environments.
For Code Generation and When Using an Analyzer
The use of dollar signs is highly situational here, particularly beneficial for code generation and when analyzing source code with an analyzer. This method allows for a more nuanced and flexible approach to code structure and organization, adapting to various programming needs.