Today we can do things like:
extension NonNullBehavior on int {
void doStuff() => print('non-null path');
}
extension NullableBehavior on int? {
void doStuff() => print('nullable path');
}
And Dart will trigger the NonNullBehavior version if the type is non-null. But creating a single declaration on a Foo? type makes completion for both Foo and Foo? display the declared members.
I'd like a way to be able to declare extension members that handle the nullable versions of a type that don't clutter the non-nullable completion list.
Say I have:
class C({var bool x, var int y, var String z});
extension E on C? {
bool isNullOrXIsFalse => this?.x ?? true;
int nullAsZeroOrY => this?.y ?? 0;
String defaultIfNullOrZ => this?.z ?? 'default';
}
Now all cases of both C and C? have those members on the completion list, but those are way longer and useless if we know the type is not null.
Today we can do things like:
And Dart will trigger the
NonNullBehaviorversion if the type is non-null. But creating a single declaration on aFoo?type makes completion for bothFooandFoo?display the declared members.I'd like a way to be able to declare extension members that handle the nullable versions of a type that don't clutter the non-nullable completion list.
Say I have:
Now all cases of both
CandC?have those members on the completion list, but those are way longer and useless if we know the type is not null.