wait<T> function
Short for Future.delayed.
Delays the execution by millisecond
milliseconds and returns value
after the delay. If value
is not provided, returns null
.
Example:
// Delay execution for 1 second.
await FlutterHelperUtils.wait(1000);
// Delay execution for 500 milliseconds and return a value.
String result = await FlutterHelperUtils.wait<String>(500, () {
return 'Delayed value';
});
Implementation
Future<T> wait<T>([
int millisecond = 1500,
FutureOr<T> Function()? value,
]) async {
await Future.delayed(Duration(milliseconds: millisecond));
return value == null ? null as T : value.call();
}