mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 23:34:24 +01:00
opt.: loading dialog
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:choice/choice.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:toolbox/core/extension/context/common.dart';
|
||||
@@ -14,11 +16,13 @@ extension DialogX on BuildContext {
|
||||
List<Widget>? actions,
|
||||
Widget? title,
|
||||
bool barrierDismiss = true,
|
||||
void Function(BuildContext)? onContext,
|
||||
}) async {
|
||||
return await showDialog<T>(
|
||||
context: this,
|
||||
barrierDismissible: barrierDismiss,
|
||||
builder: (_) {
|
||||
builder: (ctx) {
|
||||
onContext?.call(ctx);
|
||||
return AlertDialog(
|
||||
title: title,
|
||||
content: child,
|
||||
@@ -29,11 +33,28 @@ extension DialogX on BuildContext {
|
||||
);
|
||||
}
|
||||
|
||||
void showLoadingDialog({bool barrierDismiss = false}) {
|
||||
Future<T> showLoadingDialog<T>({
|
||||
required Future<T> Function() fn,
|
||||
bool barrierDismiss = false,
|
||||
}) async {
|
||||
BuildContext? ctx;
|
||||
showRoundDialog(
|
||||
child: UIs.centerSizedLoading,
|
||||
barrierDismiss: barrierDismiss,
|
||||
onContext: (c) => ctx = c,
|
||||
);
|
||||
|
||||
try {
|
||||
return await fn();
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
} finally {
|
||||
/// Wait for context to be unmounted
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
if (ctx?.mounted == true) {
|
||||
ctx?.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<String?> showPwdDialog(
|
||||
|
||||
Reference in New Issue
Block a user