diff --git a/lib/utilities/show_loading.dart b/lib/utilities/show_loading.dart index 1730df83d..371d67d1d 100644 --- a/lib/utilities/show_loading.dart +++ b/lib/utilities/show_loading.dart @@ -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 minWaitFuture( + Future future, { + required Duration delay, +}) async { + final results = await Future.wait( + [ + future, + Future.delayed(delay), + ], + ); + + return results.first as T; +} Future showLoading({ required Future whileFuture, @@ -23,6 +38,7 @@ Future showLoading({ bool rootNavigator = false, bool opaqueBG = false, void Function(Exception)? onException, + Duration? delay, }) async { unawaited( showDialog( @@ -49,7 +65,11 @@ Future showLoading({ 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",