-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
26 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
catalyst_voices/packages/catalyst_voices_shared/lib/src/utils/future_ext.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
extension FutureExt<T> on Future<T> { | ||
/// The minimum loading delay after which the state changes from loading | ||
/// to success/failure will not be perceived too jumpy. | ||
/// | ||
/// Use it to avoid showing a loading state for split second. | ||
static const Duration minimumDelay = Duration(milliseconds: 300); | ||
|
||
/// Returns the result of awaiting the [Future] | ||
/// but applies a [minimumDelay] to it. | ||
Future<T> withMinimumDelay() async { | ||
final delay = Future<void>.delayed(minimumDelay); | ||
final result = await this; | ||
await delay; | ||
return result; | ||
} | ||
} |