mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-02-03 11:46:41 +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 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../themes/stack_colors.dart';
|
import '../themes/stack_colors.dart';
|
||||||
import 'logger.dart';
|
|
||||||
import '../widgets/custom_loading_overlay.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>({
|
Future<T?> showLoading<T>({
|
||||||
required Future<T> whileFuture,
|
required Future<T> whileFuture,
|
||||||
|
@ -23,6 +38,7 @@ Future<T?> showLoading<T>({
|
||||||
bool rootNavigator = false,
|
bool rootNavigator = false,
|
||||||
bool opaqueBG = false,
|
bool opaqueBG = false,
|
||||||
void Function(Exception)? onException,
|
void Function(Exception)? onException,
|
||||||
|
Duration? delay,
|
||||||
}) async {
|
}) async {
|
||||||
unawaited(
|
unawaited(
|
||||||
showDialog<void>(
|
showDialog<void>(
|
||||||
|
@ -49,7 +65,11 @@ Future<T?> showLoading<T>({
|
||||||
T? result;
|
T? result;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (delay != null) {
|
||||||
|
result = await minWaitFuture(whileFuture, delay: delay);
|
||||||
|
} else {
|
||||||
result = await whileFuture;
|
result = await whileFuture;
|
||||||
|
}
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Logging.instance.log(
|
Logging.instance.log(
|
||||||
"showLoading caught: $e\n$s",
|
"showLoading caught: $e\n$s",
|
||||||
|
|
Loading…
Reference in a new issue