I am using an extension on Iterable
that adds the following two methods
extension MyIterableExt<T> on Iterable<T> {
bool get isEmptyOrNull => this == null || this.isEmpty;
bool get isNotEmptyOrNull => this != null && this.isNotEmpty;
}
This works as I expected, but when I try to use it in statements where the receiver can be null, I get a warning in IntelliJ. For example, the following code works and prints true
:
List<String> x;
print('${x?.reversed.isEmptyOrNull}');
Is there any way I can make the Dart Analyzer understand that the extension checks if this == null
and thus not show the warning?
Please note that I do not want to have to add suppression directives to every file or line where I use this extension!
I know I can add // ignore_for_file: can_be_null_after_null_aware
or // ignore: can_be_null_after_null_aware
to make the warning go away, but what I'm looking for is a way to make the Dart Analyzer understand that the warning for this particular extension method is not needed.
This is in a non null-safe project, if that matters.
Based on the Flutter docs, you should be able to add a comment at the top of your code that will essentially disable null safety checks:
You should be able to put that comment at the top of any specific file you want this behavior. It doesn't have to be in your "main" file.