Current status: being addressed via https://github.com/dart-lang/language/issues/41
The author of a Dart class can add more features to the class, but down-stream clients cannot easily do so.
To work with an existing class, you can write a static helper function, but it's much less convenient to call that as a function than as a method on the object. Example: helper(foo.something).somethingElse is harder to read and understand the sequencing of than foo.something.helper().somethingElse.
The best current option is to wrap the existing class in a new class which forwards members to the wrapped object, and then adds some more operations on top. It adds overhead and requires an explicit wrapping operation.
Other languages solve this problem in various ways, including extension methods and pipe operators.
Dart should do something to make it easier for users to add easily usable functionality to existing classes.
Of the proposals, #42 seems the most interesting to me. It feels the most Dart-like.
I prefer #41, it's the most intuitive and least intimidating.
Specifically for extending functionality of existing types I think #41 is the better solution among the proposals so far, despite having a higher risk of name collisions.
BTW, the first use-case from Flutter that comes to mind, which I think is also better supported by #41 is the .of pattern. I'd prefer to see context.theme and context.localizations, rather than Theme.of(context) and Localizations.of(context).
@munificent has been looking into some stats from existing Flutter code and found that .of is quite popular.
Excited to see progress on this! This would be incredibly helpful for JS interop too (https://github.com/dart-lang/sdk/issues/35084).
Closing as we shipped support for static extension methods, https://github.com/dart-lang/language/issues/41
Most helpful comment
Excited to see progress on this! This would be incredibly helpful for JS interop too (https://github.com/dart-lang/sdk/issues/35084).