张延森 3 anos atrás
pai
commit
9c7eb8c4ac

+ 5
- 1
android/app/build.gradle Ver arquivo

@@ -35,7 +35,7 @@ android {
35 35
 
36 36
     defaultConfig {
37 37
         // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
38
-        applicationId "com.example.farmer_client"
38
+        applicationId "com.njyunzhi.farmer_client"
39 39
         minSdkVersion flutter.minSdkVersion
40 40
         targetSdkVersion flutter.targetSdkVersion
41 41
         versionCode flutterVersionCode.toInteger()
@@ -65,6 +65,10 @@ android {
65 65
             // TODO: Add your own signing config for the release build.
66 66
             // Signing with the debug keys for now, so `flutter run --release` works.
67 67
             signingConfig signingConfigs.debug
68
+
69
+            //关闭混淆, 否则在运行release包后可能出现运行崩溃, TODO后续进行混淆配置
70
+            minifyEnabled false //删除无用代码
71
+            shrinkResources false //删除无用资源
68 72
         }
69 73
     }
70 74
 }

+ 1
- 1
android/app/src/debug/AndroidManifest.xml Ver arquivo

@@ -1,5 +1,5 @@
1 1
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
-    package="com.example.farmer_client">
2
+    package="com.njyunzhi.farmer_client">
3 3
     <!-- Flutter needs it to communicate with the running application
4 4
          to allow setting breakpoints, to provide hot reload, etc.
5 5
     -->

+ 1
- 1
android/app/src/main/AndroidManifest.xml Ver arquivo

@@ -1,6 +1,6 @@
1 1
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2 2
     xmlns:tools="http://schemas.android.com/tools"
3
-    package="com.example.farmer_client">
3
+    package="com.njyunzhi.farmer_client">
4 4
     <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
5 5
     <!--允许获取精确位置,精准定位必选-->
6 6
     <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

android/app/src/main/java/com/example/farmer_client/MainActivity.java → android/app/src/main/java/com/njyunzhi/farmer_client/MainActivity.java Ver arquivo

@@ -1,4 +1,4 @@
1
-package com.example.farmer_client;
1
+package com.njyunzhi.farmer_client;
2 2
 
3 3
 import io.flutter.embedding.android.FlutterActivity;
4 4
 

+ 1
- 1
android/app/src/profile/AndroidManifest.xml Ver arquivo

@@ -1,5 +1,5 @@
1 1
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
-    package="com.example.farmer_client">
2
+    package="com.njyunzhi.farmer_client">
3 3
     <!-- Flutter needs it to communicate with the running application
4 4
          to allow setting breakpoints, to provide hot reload, etc.
5 5
     -->

+ 3
- 3
ios/Runner.xcodeproj/project.pbxproj Ver arquivo

@@ -294,7 +294,7 @@
294 294
 					"$(inherited)",
295 295
 					"@executable_path/Frameworks",
296 296
 				);
297
-				PRODUCT_BUNDLE_IDENTIFIER = com.example.farmerClient;
297
+				PRODUCT_BUNDLE_IDENTIFIER = com.njyunzhi.farmerClient;
298 298
 				PRODUCT_NAME = "$(TARGET_NAME)";
299 299
 				SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
300 300
 				SWIFT_VERSION = 5.0;
@@ -422,7 +422,7 @@
422 422
 					"$(inherited)",
423 423
 					"@executable_path/Frameworks",
424 424
 				);
425
-				PRODUCT_BUNDLE_IDENTIFIER = com.example.farmerClient;
425
+				PRODUCT_BUNDLE_IDENTIFIER = com.njyunzhi.farmerClient;
426 426
 				PRODUCT_NAME = "$(TARGET_NAME)";
427 427
 				SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
428 428
 				SWIFT_OPTIMIZATION_LEVEL = "-Onone";
@@ -444,7 +444,7 @@
444 444
 					"$(inherited)",
445 445
 					"@executable_path/Frameworks",
446 446
 				);
447
-				PRODUCT_BUNDLE_IDENTIFIER = com.example.farmerClient;
447
+				PRODUCT_BUNDLE_IDENTIFIER = com.njyunzhi.farmerClient;
448 448
 				PRODUCT_NAME = "$(TARGET_NAME)";
449 449
 				SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
450 450
 				SWIFT_VERSION = 5.0;

+ 12
- 0
lib/pages/home/index.dart Ver arquivo

@@ -1,5 +1,8 @@
1
+import 'package:farmer_client/widgets/Modal.dart' as modal;
1 2
 import 'package:farmer_client/widgets/layout/BasicPage.dart';
2 3
 import 'package:flutter/material.dart';
4
+import 'package:get/get.dart';
5
+import '../../utils/timer.dart';
3 6
 import './widgets/home/index.dart';
4 7
 
5 8
 
@@ -11,6 +14,15 @@ class Home extends BasicPage {
11 14
 
12 15
   @override
13 16
   Widget builder(BuildContext context) {
17
+
18
+    setTimeout(() {
19
+      // showDialog(context: Get.overlayContext!, builder: (BuildContext c) {
20
+      //   return Modal(type: 'dialog', title: '测试', message: '这是一段 message !', onConfirm: () => print('hahahaha'),);
21
+      // } );
22
+      // Get.dialog(Modal(type: 'dialog', title: '测试', message: '这是一段 message !', onConfirm: () => print('hahahaha'),));
23
+      modal.showDialog(title: '测试', content: SizedBox(width: 300, height: 300,), onConfirm: () => false);
24
+    }, 2000);
25
+    
14 26
     return const HomePage();
15 27
   }
16 28
 }

+ 8
- 2
lib/utils/timer.dart Ver arquivo

@@ -6,7 +6,13 @@ Timer setInterval(void Function (Timer) f, int milliseconds) {
6 6
   return Timer.periodic(duration, f);
7 7
 }
8 8
 
9
-Timer setTimeout(void Function () f, int milliseconds) {
9
+void setTimeout(void Function () f, int milliseconds) {
10 10
   var duration = Duration(milliseconds: milliseconds);
11
-  return Timer(duration, f);
11
+  Timer? t = null;
12
+  t = Timer(duration, () {
13
+    if (null != t) {
14
+      t.cancel();
15
+    }
16
+    f();
17
+  });
12 18
 }

+ 105
- 26
lib/widgets/Modal.dart Ver arquivo

@@ -1,9 +1,60 @@
1 1
 
2
+import 'package:flutter/cupertino.dart';
2 3
 import 'package:flutter/material.dart';
3 4
 import 'package:flutter/widgets.dart';
4 5
 import 'package:flutter_screenutil/flutter_screenutil.dart';
6
+import 'package:get/get.dart';
5 7
 
6
-class Dialog extends StatelessWidget {
8
+typedef ModalFunc = dynamic Function();
9
+
10
+/// func 函数如果返回 bool 值, 则只有 true 的情况下才默认关闭弹窗
11
+/// 如果返回 Future , 则只有正常结束的时候 才关闭弹窗
12
+/// 其余情况, 都默认关闭弹窗
13
+void _handleFunc(ModalFunc? func) {
14
+  if (null != func) {
15
+    dynamic res = func();
16
+    if (res.runtimeType == bool) {
17
+      if (res) {
18
+        Get.back(closeOverlays: true);
19
+      }
20
+    } else if (res is Future) {
21
+      res.then((_) => Get.back(closeOverlays: true));
22
+    } else {
23
+      Get.back(closeOverlays: true);
24
+    }
25
+  } else {
26
+    Get.back(closeOverlays: true);
27
+  }
28
+}
29
+
30
+/// 打开一个 dialog
31
+void showDialog({ required String title, String? message, Widget? content, ModalFunc? onConfirm, ModalFunc? onCancel }) {
32
+  Get.dialog(
33
+    Modal(
34
+      type: 'dialog',
35
+      title: title,
36
+      message: message,
37
+      content: content,
38
+      onConfirm: () => _handleFunc(onConfirm),
39
+      onCancel: () => _handleFunc(onCancel),
40
+    )
41
+  );
42
+}
43
+
44
+/// 打开一个 alert
45
+void showAlert({ required String title, String? message, Widget? content, ModalFunc? onConfirm }) {
46
+  Get.dialog(
47
+      Modal(
48
+        type: 'alert',
49
+        title: title,
50
+        message: message,
51
+        content: content,
52
+        onConfirm: () => _handleFunc(onConfirm),
53
+      )
54
+  );
55
+}
56
+
57
+class Modal extends StatelessWidget {
7 58
 
8 59
   String title;
9 60
   String type;
@@ -12,7 +63,27 @@ class Dialog extends StatelessWidget {
12 63
   VoidCallback? onConfirm;
13 64
   VoidCallback? onCancel;
14 65
 
15
-  Dialog({Key? key,
66
+  final _titleStyle = TextStyle(color: const Color(0xFF222222), fontSize: 20.sp, fontWeight: FontWeight.bold);
67
+  final _messageStyle = TextStyle(color: const Color(0xFF666666), fontSize: 18.sp);
68
+  final _primaryColor = const Color(0xFFFF703B);
69
+  final _btnSize = Size(90.w, 36.w);
70
+  final _btnShape = RoundedRectangleBorder(
71
+    side: const BorderSide(color: Color(0xFFFF703B), width: 2.0),
72
+    borderRadius: BorderRadius.all(Radius.circular(24.5.w)),
73
+  );
74
+
75
+  void _handleConfirm() {
76
+    if (null != onConfirm) {
77
+      onConfirm!();
78
+    }
79
+  }
80
+  void _handleCancel() {
81
+    if (null != onCancel) {
82
+      onCancel!();
83
+    }
84
+  }
85
+
86
+  Modal({Key? key,
16 87
     this.type = 'alert',
17 88
     required this.title,
18 89
     this.message,
@@ -23,66 +94,74 @@ class Dialog extends StatelessWidget {
23 94
 
24 95
   Widget _confirmBtn() {
25 96
     return ElevatedButton(
26
-      child: const Text("确定"),
97
+      child: Text("确定", style: TextStyle(color: Colors.white, fontSize: 18.sp, letterSpacing: 5.sp)),
27 98
       style: ElevatedButton.styleFrom(
28
-          primary: const Color(0xFFFF703B),
29
-          textStyle: TextStyle(color: Colors.white, fontSize: 20.sp, letterSpacing: 5.sp),
99
+          primary: _primaryColor,
30 100
           elevation: 0,
31
-          minimumSize: Size(90.w, 49.w),
32
-          shape: RoundedRectangleBorder(
33
-            borderRadius: BorderRadius.all(Radius.circular(24.5.w)),
34
-          )
101
+          minimumSize: _btnSize,
102
+          shape: _btnShape,
35 103
       ),
36
-      onPressed: onConfirm,
104
+      onPressed: _handleConfirm,
37 105
     );
38 106
   }
39 107
 
40 108
   Widget _cancelBtn() {
41 109
     return ElevatedButton(
42
-      child: const Text("取消"),
110
+      child: Text("取消", style: TextStyle(color: _primaryColor, fontSize: 18.sp, letterSpacing: 5.sp)),
43 111
       style: ElevatedButton.styleFrom(
44
-        primary: Colors.transparent,
45
-        textStyle: TextStyle(color: const Color(0xFFFF703B), fontSize: 20.sp, letterSpacing: 5.sp),
112
+        primary: Colors.white,
46 113
         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
-        )
114
+        minimumSize: _btnSize,
115
+        shape: _btnShape,
52 116
       ),
53
-      onPressed: onCancel,
117
+      onPressed: _handleCancel,
54 118
     );
55 119
   }
56 120
 
57 121
   Widget _alert() {
58 122
     return SimpleDialog(
59
-      title: Text(title),
123
+      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(24.w)),
124
+      titleTextStyle: _titleStyle,
125
+      title: Text(title, textAlign: TextAlign.center),
60 126
         children: [
61
-          if (null != message) Text(message!),
127
+          if (null != message) Text(message!, textAlign: TextAlign.center, style: _messageStyle),
62 128
           if (null != content) content!,
129
+          SizedBox(height: 16.w),
63 130
           Center(
64 131
             child: _confirmBtn(),
65
-          )
132
+          ),
133
+          SizedBox(height: 10.w),
66 134
         ]
67 135
     );
68 136
   }
69 137
 
70 138
   Widget _dialog() {
139
+    Widget hSpacer = SizedBox(width: 16.w);
140
+
71 141
     return SimpleDialog(
72
-        title: Text(title),
142
+        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(24.w)),
143
+        titleTextStyle: _titleStyle,
144
+        title: Text(title, textAlign: TextAlign.center),
145
+        alignment: Alignment.center,
73 146
         children: [
74
-          if (null != message) Text(message!),
147
+          if (null != message) Text(message!, textAlign: TextAlign.center, style: _messageStyle),
75 148
           if (null != content) content!,
149
+          SizedBox(height: 16.w),
76 150
           Row(
151
+            mainAxisAlignment: MainAxisAlignment.center,
77 152
             children: [
153
+              hSpacer,
78 154
               Center(
79 155
                 child: _confirmBtn(),
80 156
               ),
157
+              hSpacer,
81 158
               Center(
82 159
                 child: _cancelBtn(),
83
-              )
160
+              ),
161
+              hSpacer,
84 162
             ],
85
-          )
163
+          ),
164
+          SizedBox(height: 10.w),
86 165
         ]
87 166
     );
88 167
   }