mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-08 19:59:29 +00:00
add minimum wait time option
This commit is contained in:
parent
cae27b3835
commit
d66e0580ec
1 changed files with 22 additions and 2 deletions
|
@ -11,9 +11,24 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../themes/stack_colors.dart';
|
||||
import 'logger.dart';
|
||||
import '../widgets/custom_loading_overlay.dart';
|
||||
import 'logger.dart';
|
||||
|
||||
Future<T> minWaitFuture<T>(
|
||||
Future<T> future, {
|
||||
required Duration delay,
|
||||
}) async {
|
||||
final results = await Future.wait(
|
||||
[
|
||||
future,
|
||||
Future<dynamic>.delayed(delay),
|
||||
],
|
||||
);
|
||||
|
||||
return results.first as T;
|
||||
}
|
||||
|
||||
Future<T?> showLoading<T>({
|
||||
required Future<T> whileFuture,
|
||||
|
@ -23,6 +38,7 @@ Future<T?> showLoading<T>({
|
|||
bool rootNavigator = false,
|
||||
bool opaqueBG = false,
|
||||
void Function(Exception)? onException,
|
||||
Duration? delay,
|
||||
}) async {
|
||||
unawaited(
|
||||
showDialog<void>(
|
||||
|
@ -49,7 +65,11 @@ Future<T?> showLoading<T>({
|
|||
T? result;
|
||||
|
||||
try {
|
||||
result = await whileFuture;
|
||||
if (delay != null) {
|
||||
result = await minWaitFuture(whileFuture, delay: delay);
|
||||
} else {
|
||||
result = await whileFuture;
|
||||
}
|
||||
} catch (e, s) {
|
||||
Logging.instance.log(
|
||||
"showLoading caught: $e\n$s",
|
||||
|
|
Loading…
Reference in a new issue