Skip to main content

avoid-nullable-async-value-pattern

effort: 2m
starter+

Warns when a potentially nullable AsyncValue inside a pattern is does not have a hasValue: true check.

Example

❌ Bad:

void fn() {
switch (...) {
// LINT: Using ':final value?' on a possibly nullable value is unsafe.
// Try using ':final value, hasValue: true' instead.
case AsyncValue<int?>(:final value?):
print(value);

// LINT: Using ':final value?' on a possibly nullable value is unsafe.
// Try using ':final value, hasValue: true' instead.
case AsyncError<int?>(:final value?):
print(value);

// LINT: Using ':final value?' on a possibly nullable value is unsafe.
// Try using ':final value, hasValue: true' instead.
case AsyncLoading<int?>(:final value?):
print(value);
}
}

✅ Good:

void fn() {
switch (...) {
case AsyncValue<int?>(:final value, hasValue: true):
print(value);
}
}