Future<T>.value constructor Null safety

  1. [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 the value is required, otherwise the construction throws.

Use Completer to create a future and complete it later.


factory Future.value([FutureOr<T>? value]) {
  return new _Future<T>.immediate(value == null ? value as T : value);