|
@@ -1,3 +1,5 @@
|
|
1
|
+import 'dart:ffi';
|
|
2
|
+
|
1
|
3
|
import 'package:flutter/cupertino.dart';
|
2
|
4
|
import 'package:flutter/material.dart';
|
3
|
5
|
import 'package:flutter/widgets.dart';
|
|
@@ -9,26 +11,37 @@ typedef ModalFunc = dynamic Function();
|
9
|
11
|
/// func 函数如果返回 bool 值, 则只有 true 的情况下才默认关闭弹窗
|
10
|
12
|
/// 如果返回 Future , 则只有正常结束的时候 才关闭弹窗
|
11
|
13
|
/// 其余情况, 都默认关闭弹窗
|
12
|
|
-void _handleFunc(ModalFunc? func) {
|
|
14
|
+void _handleFunc(ModalFunc? func, bool lazy) {
|
|
15
|
+ // 是否立即关闭
|
|
16
|
+ _close (bool canClose) {
|
|
17
|
+ if (canClose) {
|
|
18
|
+ _closeModal();
|
|
19
|
+ }
|
|
20
|
+ };
|
|
21
|
+
|
|
22
|
+ // 如果 lazy 是 true 则不会立即关闭
|
|
23
|
+ _close(!lazy);
|
|
24
|
+
|
13
|
25
|
if (null != func) {
|
14
|
26
|
dynamic res = func();
|
15
|
27
|
if (res.runtimeType == bool) {
|
16
|
|
- if (res) {
|
17
|
|
- _closeModal();
|
|
28
|
+ if (res && lazy) {
|
|
29
|
+ _close(lazy);
|
18
|
30
|
}
|
19
|
31
|
} else if (res is Future) {
|
20
|
|
- res.then((_) => _closeModal());
|
|
32
|
+ res.then((_) => _close(lazy));
|
21
|
33
|
} else {
|
22
|
|
- _closeModal();
|
|
34
|
+ _close(lazy);
|
23
|
35
|
}
|
24
|
36
|
} else {
|
25
|
|
- _closeModal();
|
|
37
|
+ _close(lazy);
|
26
|
38
|
}
|
27
|
39
|
}
|
28
|
40
|
|
29
|
41
|
/// 打开一个 dialog
|
30
|
42
|
void showDialog(
|
31
|
43
|
{required String title,
|
|
44
|
+ lazy = false,
|
32
|
45
|
String? message,
|
33
|
46
|
Widget? content,
|
34
|
47
|
ModalFunc? onConfirm,
|
|
@@ -38,14 +51,15 @@ void showDialog(
|
38
|
51
|
title: title,
|
39
|
52
|
message: message,
|
40
|
53
|
content: content,
|
41
|
|
- onConfirm: () => _handleFunc(onConfirm),
|
42
|
|
- onCancel: () => _handleFunc(onCancel),
|
|
54
|
+ onConfirm: () => _handleFunc(onConfirm, lazy),
|
|
55
|
+ onCancel: () => _handleFunc(onCancel, lazy),
|
43
|
56
|
));
|
44
|
57
|
}
|
45
|
58
|
|
46
|
59
|
/// 打开一个 alert
|
47
|
60
|
void showAlert(
|
48
|
61
|
{required String title,
|
|
62
|
+ bool lazy = false,
|
49
|
63
|
String? message,
|
50
|
64
|
Widget? content,
|
51
|
65
|
ModalFunc? onConfirm}) {
|
|
@@ -54,7 +68,7 @@ void showAlert(
|
54
|
68
|
title: title,
|
55
|
69
|
message: message,
|
56
|
70
|
content: content,
|
57
|
|
- onConfirm: () => _handleFunc(onConfirm),
|
|
71
|
+ onConfirm: () => _handleFunc(onConfirm, lazy),
|
58
|
72
|
));
|
59
|
73
|
}
|
60
|
74
|
|