Skip to main content

future_sync_value

Details about the 'future_sync_value' diagnostic produced by the Dart analyzer.

For synchronous values, Future.syncValue is more performant.

Description

#

The analyzer produces this diagnostic when the method Future.value is called with a non-Future value. This includes the type Object, but not dynamic or FutureOr.

The constructor internally checks whether the argument is a Future. If the argument is already known not to be a Future, the check is redundant and reduces performance.

Example

#
dart
Future<int> f() => Future.value(1);

Common fixes

#

Replace the call to Future.value with a call to Future.syncValue:

dart
Future<int> f() => Future.syncValue(1);