delayed<T> method
Executes a callback function after the current duration has passed.
The callback is an optional function that returns a FutureOr<T>,
allowing for both synchronous and asynchronous operations within the
callback. If no callback is provided, the method simply waits for the
duration to complete before resolving the returned Future.
The method returns a Future<T> which completes after the duration has
elapsed and the callback (if provided) has finished executing.
Usage:
Duration(seconds: 3).delayed(() {
// This callback is executed after a delay of 3 seconds.
return 'Result after delay';
}).then((result) {
print(result); // Prints: 'Result after delay'
});
Implementation
Future<T> delayed<T>([FutureOr<T> Function()? callback]) =>
Future<T>.delayed(this, callback);