Skip to main content

prefer-correct-future-return-type

has auto-fix
pro+

Warns when a declaration that returns a Future has an incorrect return type.

Object, dynamic, generic type, FutureOr or a nullable Future are considered incorrect and should be replaced by a Future.

Example

❌ Bad:

// LINT: This return type is expected to be a non-nullable 'Future'. Try changing it.
dynamic function() async => ...;

// LINT: This return type is expected to be a non-nullable 'Future'. Try changing it.
Object function() async => ...;

// LINT: This return type is expected to be a non-nullable 'Future'. Try changing it.
FutureOr<int> function() async => ...;

// LINT: This return type is expected to be a non-nullable 'Future'. Try changing it.
Future<int>? function() async => ...;

// LINT: This return type is expected to be a non-nullable 'Future'. Try changing it.
T function<T>() async => ...;

✅ Good:

Future<dynamic> function() async => ...;

Future<Object> function() async => ...;

Future<int> function() async => ...;

Future<int> function() async => ...;

Future<T> function<T>() async => ...;