prefer-specifying-future-value-type
Warns when a Future.value
invocation gets a nullable argument, but the expected type is not nullable.
If such Future.value
invocation receives null
at runtime, it will throw an exception because the expected type it not nullable.
Example
❌ Bad:
void fn(int? nullable) {
// LINT: This Future can throw at runtime because the provided value is nullable, but the expected type is not.
// Try specifying the type argument as nullable or passing a non-nullable value.
final int value = Future.value(nullable);
// LINT: This Future can throw at runtime because the provided value is nullable, but the expected type is not.
// Try specifying the type argument as nullable or passing a non-nullable value.
final value = Future<int>.value(nullable);
}
✅ Good:
void fn(int? nullable) {
final value = Future.value(1);
final value = Future<int?>.value(nullable);
}