stack_wallet/lib/utilities/show_loading.dart

44 lines
1.1 KiB
Dart
Raw Normal View History

2023-02-23 22:59:58 +00:00
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart';
import 'package:stackwallet/widgets/custom_loading_overlay.dart';
Future<T> showLoading<T>({
required Future<T> whileFuture,
required BuildContext context,
required String message,
String? subMessage,
bool isDesktop = false,
}) async {
unawaited(
showDialog<void>(
context: context,
barrierDismissible: false,
builder: (_) => WillPopScope(
onWillPop: () async => false,
child: Container(
color: Theme.of(context)
.extension<StackColors>()!
.overlay
.withOpacity(0.6),
child: CustomLoadingOverlay(
message: message,
subMessage: subMessage,
eventBus: null,
),
),
),
),
);
final result = await whileFuture;
// TODO: update to flutter 3.7.x to take advantage of context.mounted
// if (mounted) {
Navigator.of(context, rootNavigator: isDesktop).pop();
// }
return result;
}