瀏覽代碼

Merge branch 'master' of http://git.ycjcjy.com/nanyang/farmer_client

[baozhangchao] 3 年之前
父節點
當前提交
7aa03ac15d
共有 2 個檔案被更改,包括 25 行新增11 行删除
  1. 23
    9
      lib/widgets/Modal.dart
  2. 2
    2
      pubspec.lock

+ 23
- 9
lib/widgets/Modal.dart 查看文件

@@ -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
 

+ 2
- 2
pubspec.lock 查看文件

@@ -185,7 +185,7 @@ packages:
185 185
     dependency: "direct main"
186 186
     description:
187 187
       name: flutter_easyloading
188
-      url: "https://pub.dartlang.org"
188
+      url: "https://pub.flutter-io.cn"
189 189
     source: hosted
190 190
     version: "3.0.3"
191 191
   flutter_easyrefresh:
@@ -225,7 +225,7 @@ packages:
225 225
     dependency: transitive
226 226
     description:
227 227
       name: flutter_spinkit
228
-      url: "https://pub.dartlang.org"
228
+      url: "https://pub.flutter-io.cn"
229 229
     source: hosted
230 230
     version: "5.1.0"
231 231
   flutter_test: