张延森 3 år sedan
förälder
incheckning
e8f0371d2b
2 ändrade filer med 95 tillägg och 11 borttagningar
  1. 0
    11
      lib/widgets/Dialog.dart
  2. 95
    0
      lib/widgets/Modal.dart

+ 0
- 11
lib/widgets/Dialog.dart Visa fil

@@ -1,11 +0,0 @@
1
-
2
-import 'package:flutter/widgets.dart';
3
-
4
-class Dialog extends StatelessWidget {
5
-  @override
6
-  Widget build(BuildContext context) {
7
-    // TODO: implement build
8
-    throw UnimplementedError();
9
-  }
10
-
11
-}

+ 95
- 0
lib/widgets/Modal.dart Visa fil

@@ -0,0 +1,95 @@
1
+
2
+import 'package:flutter/material.dart';
3
+import 'package:flutter/widgets.dart';
4
+import 'package:flutter_screenutil/flutter_screenutil.dart';
5
+
6
+class Dialog extends StatelessWidget {
7
+
8
+  String title;
9
+  String type;
10
+  String? message;
11
+  Widget? content;
12
+  VoidCallback? onConfirm;
13
+  VoidCallback? onCancel;
14
+
15
+  Dialog({Key? key,
16
+    this.type = 'alert',
17
+    required this.title,
18
+    this.message,
19
+    this.content,
20
+    this.onConfirm,
21
+    this.onCancel,
22
+  }): super(key: key);
23
+
24
+  Widget _confirmBtn() {
25
+    return ElevatedButton(
26
+      child: const Text("确定"),
27
+      style: ElevatedButton.styleFrom(
28
+          primary: const Color(0xFFFF703B),
29
+          textStyle: TextStyle(color: Colors.white, fontSize: 20.sp, letterSpacing: 5.sp),
30
+          elevation: 0,
31
+          minimumSize: Size(90.w, 49.w),
32
+          shape: RoundedRectangleBorder(
33
+            borderRadius: BorderRadius.all(Radius.circular(24.5.w)),
34
+          )
35
+      ),
36
+      onPressed: onConfirm,
37
+    );
38
+  }
39
+
40
+  Widget _cancelBtn() {
41
+    return ElevatedButton(
42
+      child: const Text("取消"),
43
+      style: ElevatedButton.styleFrom(
44
+        primary: Colors.transparent,
45
+        textStyle: TextStyle(color: const Color(0xFFFF703B), fontSize: 20.sp, letterSpacing: 5.sp),
46
+        elevation: 0,
47
+        minimumSize: Size(90.w, 49.w),
48
+        shape: RoundedRectangleBorder(
49
+          side: const BorderSide(color: Color(0xFFFF703B), width: 2.0),
50
+          borderRadius: BorderRadius.all(Radius.circular(24.5.w)),
51
+        )
52
+      ),
53
+      onPressed: onCancel,
54
+    );
55
+  }
56
+
57
+  Widget _alert() {
58
+    return SimpleDialog(
59
+      title: Text(title),
60
+        children: [
61
+          if (null != message) Text(message!),
62
+          if (null != content) content!,
63
+          Center(
64
+            child: _confirmBtn(),
65
+          )
66
+        ]
67
+    );
68
+  }
69
+
70
+  Widget _dialog() {
71
+    return SimpleDialog(
72
+        title: Text(title),
73
+        children: [
74
+          if (null != message) Text(message!),
75
+          if (null != content) content!,
76
+          Row(
77
+            children: [
78
+              Center(
79
+                child: _confirmBtn(),
80
+              ),
81
+              Center(
82
+                child: _cancelBtn(),
83
+              )
84
+            ],
85
+          )
86
+        ]
87
+    );
88
+  }
89
+
90
+  @override
91
+  Widget build(BuildContext context) {
92
+    return type == 'alert' ? _alert() : _dialog();
93
+  }
94
+
95
+}