Future<T>.value constructor
- [FutureOr<
T> ? value]
Creates a future completed with value
.
If value
is a future, the created future waits for the value
future to complete, and then completes with the same result. Since a value
future can complete with an error, so can the future created by Future.value, even if the name suggests otherwise.
If value
is not a Future, the created future is completed with the value
value, equivalently to new Future<T>.sync(() => value)
.
If value
is omitted or null
, it is converted to FutureOr<T>
by value as FutureOr<T>
. If T
is not nullable, then a non-null
value
must be provided, otherwise the construction throws.
Use Completer to create a future now and complete it later.
Implementation
@pragma("vm:entry-point") @pragma("vm:prefer-inline") factory Future.value([FutureOr<T>? value]) { return new _Future<T>.immediate(value == null ? value as T : value); }
© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dart.dev/stable/2.13.0/dart-async/Future/Future.value.html