sdk
sdk copied to clipboard
Cascading and callable
- Dart analyzer and linter
Callable is not compatible with cascading.
In my case it is used as an init() lifecycle but I want to keep the reference
of the A instance.
If force 2 lines declaration and it's surprising to have
to make a direct reference to call.
Thanks!
void main() {
A()..call('OK');
A()..('Fail');
}
class A {
call(String s) {
...
}
}
Summary: The Dart analyzer and linter flag an error when using the call method with cascading syntax. This is because the call method is not compatible with cascading, which leads to unexpected behavior and forces users to write code in a less concise way.
Correct, you have to use .call. Same for o?.call(...).
The latter has advantages over o?(...) in the it doesn't conflict with the conditional operator so easily.
There are no current plans to allow (...) after a .. or ?.. Definitely not after ?., and probably not after just one of them either.
It saddens me but they're reasons and these are the specs. Thanks!