Yansen 2 anos atrás
pai
commit
6b9fd36ebe

+ 2
- 1
lib/pages/userInfo/index.dart Ver arquivo

@@ -51,12 +51,13 @@ class UserInfo extends BasicPage {
51 51
         EasyLoading.show(status: '数据加载中...');
52 52
 
53 53
         getCurrent().then((person) {
54
+          EasyLoading.dismiss();
54 55
           userInfo.user(Person.fromJson(person));
55 56
           Fluttertoast.showToast(msg: '保存成功');
56
-          EasyLoading.dismiss();
57 57
 
58 58
           Get.offAllNamed('/main');
59 59
         }).catchError((e) {
60
+          EasyLoading.dismiss();
60 61
           EasyLoading.showError('出错啦!');
61 62
           print(e);
62 63
         });

+ 5
- 13
lib/services/address.dart Ver arquivo

@@ -1,7 +1,7 @@
1 1
 import 'package:dio/dio.dart';
2 2
 import 'package:farmer_client/utils/Request.dart';
3
-import 'package:fluttertoast/fluttertoast.dart';
4 3
 
4
+import 'showError.dart';
5 5
 /**
6 6
  * 地址列表
7 7
  * @param {*} data
@@ -19,9 +19,7 @@ Future getAddress() async {
19 19
 Future addressSave(String address) async {
20 20
   return request('/address',
21 21
           options: Options(method: 'POST'), data: {'address': address})
22
-      .catchError((error) => {
23
-            Fluttertoast.showToast(msg: error.error['message']),
24
-          });
22
+      .catchError(showError);
25 23
 }
26 24
 
27 25
 /**
@@ -31,9 +29,7 @@ Future addressSave(String address) async {
31 29
  */
32 30
 Future addressDelete(String id) async {
33 31
   return request('/address/$id', options: Options(method: 'DELETE'))
34
-      .catchError((error) => {
35
-            Fluttertoast.showToast(msg: error.error['message']),
36
-          });
32
+      .catchError(showError);
37 33
 }
38 34
 
39 35
 /**
@@ -44,9 +40,7 @@ Future addressDelete(String id) async {
44 40
 Future addressUpdate(String id, String address) async {
45 41
   return request('/address/$id',
46 42
           options: Options(method: 'PUT'), data: {'address': address})
47
-      .catchError((error) => {
48
-            Fluttertoast.showToast(msg: error.error['message']),
49
-          });
43
+      .catchError(showError);
50 44
 }
51 45
 
52 46
 /**
@@ -56,7 +50,5 @@ Future addressUpdate(String id, String address) async {
56 50
  */
57 51
 Future addressDefault(String id) async {
58 52
   return request('/address/$id/default', options: Options(method: 'PUT'))
59
-      .catchError((error) => {
60
-            Fluttertoast.showToast(msg: error.error['message']),
61
-          });
53
+      .catchError(showError);
62 54
 }

+ 5
- 13
lib/services/homeAPI.dart Ver arquivo

@@ -1,7 +1,7 @@
1 1
 import 'package:dio/dio.dart';
2 2
 import 'package:farmer_client/utils/Request.dart';
3
-import 'package:fluttertoast/fluttertoast.dart';
4 3
 
4
+import 'showError.dart';
5 5
 /**
6 6
  * banner轮播图
7 7
  * @param {*} data
@@ -11,9 +11,7 @@ import 'package:fluttertoast/fluttertoast.dart';
11 11
 Future getHomeBanner(String position) async {
12 12
   return request('/banner',
13 13
           options: Options(method: 'GET'), data: {'position': position})
14
-      .catchError((error) => {
15
-            Fluttertoast.showToast(msg: error.error['message']),
16
-          });
14
+      .catchError(showError);
17 15
 }
18 16
 
19 17
 /**
@@ -24,9 +22,7 @@ Future getHomeBanner(String position) async {
24 22
 Future getMachinery(params) async {
25 23
   return request('/machinery',
26 24
           options: Options(method: 'GET'), queryParameters: params)
27
-      .catchError((error) => {
28
-            Fluttertoast.showToast(msg: error.error['message']),
29
-          });
25
+      .catchError(showError);
30 26
 }
31 27
 
32 28
 /**
@@ -39,9 +35,7 @@ Future searchMachinery(params) async {
39 35
           options: Options(method: 'GET'),
40 36
           queryParameters: params,
41 37
           data: params)
42
-      .catchError((error) => {
43
-            Fluttertoast.showToast(msg: error.error['message']),
44
-          });
38
+      .catchError(showError);
45 39
 }
46 40
 
47 41
 /**
@@ -62,9 +56,7 @@ Future typeMachinery(
62 56
       data: {
63 57
         'typeId': typeId,
64 58
         'location': location
65
-      }).catchError((error) => {
66
-        Fluttertoast.showToast(msg: error.error['message']),
67
-      });
59
+      }).catchError(showError);
68 60
 }
69 61
 
70 62
 /**

+ 2
- 4
lib/services/main.dart Ver arquivo

@@ -1,7 +1,7 @@
1 1
 import 'package:dio/dio.dart';
2 2
 import 'package:farmer_client/utils/Request.dart';
3
-import 'package:fluttertoast/fluttertoast.dart';
4 3
 
4
+import 'showError.dart';
5 5
 /**
6 6
  * 意见反馈
7 7
  * @param {*} data
@@ -11,7 +11,5 @@ import 'package:fluttertoast/fluttertoast.dart';
11 11
 Future feedback(String content) async {
12 12
   return request('/feedback',
13 13
           options: Options(method: 'POST'), data: {'content': content})
14
-      .catchError((error) => {
15
-            Fluttertoast.showToast(msg: error.error['message']),
16
-          });
14
+      .catchError(showError);
17 15
 }

+ 3
- 7
lib/services/news.dart Ver arquivo

@@ -1,7 +1,7 @@
1 1
 import 'package:dio/dio.dart';
2 2
 import 'package:farmer_client/utils/Request.dart';
3
-import 'package:fluttertoast/fluttertoast.dart';
4 3
 
4
+import 'showError.dart';
5 5
 /**
6 6
  * 农机资讯
7 7
  * @param {*} data
@@ -9,9 +9,7 @@ import 'package:fluttertoast/fluttertoast.dart';
9 9
  */
10 10
 Future getNewsList(params) async {
11 11
   return request('/news', options: Options(method: 'GET'),queryParameters: params)
12
-      .catchError((error) => {
13
-            Fluttertoast.showToast(msg: error.error['message']),
14
-          });
12
+      .catchError(showError);
15 13
 }
16 14
 
17 15
 /**
@@ -23,7 +21,5 @@ Future getNewsInfo(String id) async {
23 21
   return request(
24 22
     '/news/$id',
25 23
     options: Options(method: 'GET'),
26
-  ).catchError((error) => {
27
-        Fluttertoast.showToast(msg: error.error['message']),
28
-      });
24
+  ).catchError(showError);
29 25
 }

+ 7
- 19
lib/services/orderAPI.dart Ver arquivo

@@ -1,7 +1,7 @@
1 1
 import 'package:dio/dio.dart';
2 2
 import 'package:farmer_client/utils/Request.dart';
3
-import 'package:fluttertoast/fluttertoast.dart';
4 3
 
4
+import 'showError.dart';
5 5
 /**
6 6
  * 订单列表
7 7
  * @param {*} data
@@ -10,9 +10,7 @@ import 'package:fluttertoast/fluttertoast.dart';
10 10
 Future getOrderList(params) async {
11 11
   return request('/order',
12 12
           options: Options(method: 'GET'), queryParameters: params)
13
-      .catchError((error) => {
14
-            Fluttertoast.showToast(msg: error.error['message']),
15
-          });
13
+      .catchError(showError);
16 14
 }
17 15
 
18 16
 /**
@@ -24,9 +22,7 @@ Future orderInfo(String id) async {
24 22
   return request(
25 23
     '/order/$id',
26 24
     options: Options(method: 'GET'),
27
-  ).catchError((error) => {
28
-        Fluttertoast.showToast(msg: error.error['message']),
29
-      });
25
+  ).catchError(showError);
30 26
 }
31 27
 
32 28
 /**
@@ -37,9 +33,7 @@ Future orderInfo(String id) async {
37 33
 
38 34
 Future generateOrder(item) async {
39 35
   return request('/order', options: Options(method: 'POST'), data: item)
40
-      .catchError((error) => {
41
-            Fluttertoast.showToast(msg: error.error['message']),
42
-          });
36
+      .catchError(showError);
43 37
 }
44 38
 
45 39
 /**
@@ -49,9 +43,7 @@ Future generateOrder(item) async {
49 43
  */
50 44
 Future orderDelete(String id) async {
51 45
   return request('/order/$id', options: Options(method: 'DELETE'))
52
-      .catchError((error) => {
53
-            Fluttertoast.showToast(msg: error.error['message']),
54
-          });
46
+      .catchError(showError);
55 47
 }
56 48
 
57 49
 /**
@@ -61,9 +53,7 @@ Future orderDelete(String id) async {
61 53
  */
62 54
 Future orderRefund(String id) async {
63 55
   return request('/order/$id/refund', options: Options(method: 'PUT'))
64
-      .catchError((error) => {
65
-            Fluttertoast.showToast(msg: error.error['message']),
66
-          });
56
+      .catchError(showError);
67 57
 }
68 58
 
69 59
 /**
@@ -76,7 +66,5 @@ Future orderEvaluation(String orderId, num score, String content) async {
76 66
   return request('/evaluation',
77 67
           options: Options(method: 'POST'),
78 68
           data: {'orderId': orderId, 'score': score, 'content': content})
79
-      .catchError((error) => {
80
-            Fluttertoast.showToast(msg: error.error['message']),
81
-          });
69
+      .catchError(showError);
82 70
 }

+ 0
- 1
lib/services/pay.dart Ver arquivo

@@ -1,6 +1,5 @@
1 1
 import 'package:dio/dio.dart';
2 2
 import 'package:farmer_client/utils/Request.dart';
3
-import 'package:fluttertoast/fluttertoast.dart';
4 3
 
5 4
 /**
6 5
  * 支付

+ 10
- 0
lib/services/showError.dart Ver arquivo

@@ -0,0 +1,10 @@
1
+
2
+import 'package:flutter_easyloading/flutter_easyloading.dart';
3
+import 'package:fluttertoast/fluttertoast.dart';
4
+
5
+void showError(error) {
6
+  var err = error.error;
7
+  var msg = err is Map ? err['message'] : err;
8
+  EasyLoading.dismiss();
9
+  Fluttertoast.showToast(msg: msg);
10
+}

+ 5
- 9
lib/services/user.dart Ver arquivo

@@ -2,14 +2,14 @@ import 'package:dio/dio.dart';
2 2
 import 'package:farmer_client/utils/Request.dart';
3 3
 import 'package:fluttertoast/fluttertoast.dart';
4 4
 
5
+import 'showError.dart';
6
+
5 7
 Future getSMSCaptch(String phone) async {
6 8
   return request('/sms-captcha',
7 9
       options: Options(method: 'POST'),
8 10
       queryParameters: {'phone': phone}).then((value) {
9 11
     Fluttertoast.showToast(msg: '验证码发送成功!');
10
-  }).catchError((error) {
11
-    Fluttertoast.showToast(msg: error.error['message']);
12
-  });
12
+  }).catchError(showError);
13 13
 }
14 14
 
15 15
 //登录
@@ -18,9 +18,7 @@ Future userLogin(String userName, String password) async {
18 18
     '/login',
19 19
     options: Options(method: 'POST'),
20 20
     data: {'userName': userName, 'password': password},
21
-  ).catchError((error) => {
22
-        Fluttertoast.showToast(msg: error['message']),
23
-      });
21
+  ).catchError(showError);
24 22
 }
25 23
 
26 24
 Future getCurrent() async {
@@ -34,7 +32,5 @@ Future getCurrent() async {
34 32
  */
35 33
 Future updateInfo(String id, userdata) async {
36 34
   return request('/person/$id', options: Options(method: 'PUT'), data: userdata)
37
-      .catchError((error) => {
38
-            Fluttertoast.showToast(msg: error.error['message']),
39
-          });
35
+      .catchError(showError);
40 36
 }