withMinDuration method
Ensures that resolving this value takes at least a specified duration.
This is useful for preventing UI elements like loading spinners from flickering on and off too quickly.
If duration is null, this method returns the original value
immediately.
Implementation
FutureOr<T> withMinDuration(Duration? duration) {
if (duration == null) {
return this;
}
return Future.wait([
Future.value(this),
Future<void>.delayed(duration),
]).then((e) => e.first as T);
}