Future.delayed(Duration duration, [ dynamic computation() ])

Creates a future that runs its computation after a delay.

The computation will be executed after the given duration has passed, and the future is completed with the result. If the duration is 0 or less, it completes no sooner than in the next event-loop iteration.

If computation is omitted, it will be treated as if computation was set to () => null, and the future will eventually complete with the null value.

If calling computation throws, the created future will complete with the error.

See also Completer for a way to create and complete a future at a later time that isn't necessarily after a known fixed duration.

Source

factory Future.delayed(Duration duration, [computation()]) {
  _Future<T> result = new _Future<T>();
  new Timer(duration, () {
    try {
      result._complete(computation?.call());
    } catch (e, s) {
      _completeWithErrorCallback(result, e, s);
    }
  });
  return result;
}