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
#Future<int> f() => Future.value(1);
Common fixes
#
Replace the call to Future.value with a call to
Future.syncValue:
Future<int> f() => Future.syncValue(1);
除非另有说明,文档之所提及适用于 Dart 3.12.2 版本报告页面问题.