Yansen 2 years ago
parent
commit
6b9fd36ebe

+ 2
- 1
lib/pages/userInfo/index.dart View File

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

+ 5
- 13
lib/services/address.dart View File

1
 import 'package:dio/dio.dart';
1
 import 'package:dio/dio.dart';
2
 import 'package:farmer_client/utils/Request.dart';
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
  * @param {*} data
7
  * @param {*} data
19
 Future addressSave(String address) async {
19
 Future addressSave(String address) async {
20
   return request('/address',
20
   return request('/address',
21
           options: Options(method: 'POST'), data: {'address': address})
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
  */
29
  */
32
 Future addressDelete(String id) async {
30
 Future addressDelete(String id) async {
33
   return request('/address/$id', options: Options(method: 'DELETE'))
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
 Future addressUpdate(String id, String address) async {
40
 Future addressUpdate(String id, String address) async {
45
   return request('/address/$id',
41
   return request('/address/$id',
46
           options: Options(method: 'PUT'), data: {'address': address})
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
  */
50
  */
57
 Future addressDefault(String id) async {
51
 Future addressDefault(String id) async {
58
   return request('/address/$id/default', options: Options(method: 'PUT'))
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 View File

1
 import 'package:dio/dio.dart';
1
 import 'package:dio/dio.dart';
2
 import 'package:farmer_client/utils/Request.dart';
2
 import 'package:farmer_client/utils/Request.dart';
3
-import 'package:fluttertoast/fluttertoast.dart';
4
 
3
 
4
+import 'showError.dart';
5
 /**
5
 /**
6
  * banner轮播图
6
  * banner轮播图
7
  * @param {*} data
7
  * @param {*} data
11
 Future getHomeBanner(String position) async {
11
 Future getHomeBanner(String position) async {
12
   return request('/banner',
12
   return request('/banner',
13
           options: Options(method: 'GET'), data: {'position': position})
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
 Future getMachinery(params) async {
22
 Future getMachinery(params) async {
25
   return request('/machinery',
23
   return request('/machinery',
26
           options: Options(method: 'GET'), queryParameters: params)
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
           options: Options(method: 'GET'),
35
           options: Options(method: 'GET'),
40
           queryParameters: params,
36
           queryParameters: params,
41
           data: params)
37
           data: params)
42
-      .catchError((error) => {
43
-            Fluttertoast.showToast(msg: error.error['message']),
44
-          });
38
+      .catchError(showError);
45
 }
39
 }
46
 
40
 
47
 /**
41
 /**
62
       data: {
56
       data: {
63
         'typeId': typeId,
57
         'typeId': typeId,
64
         'location': location
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 View File

1
 import 'package:dio/dio.dart';
1
 import 'package:dio/dio.dart';
2
 import 'package:farmer_client/utils/Request.dart';
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
  * @param {*} data
7
  * @param {*} data
11
 Future feedback(String content) async {
11
 Future feedback(String content) async {
12
   return request('/feedback',
12
   return request('/feedback',
13
           options: Options(method: 'POST'), data: {'content': content})
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 View File

1
 import 'package:dio/dio.dart';
1
 import 'package:dio/dio.dart';
2
 import 'package:farmer_client/utils/Request.dart';
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
  * @param {*} data
7
  * @param {*} data
9
  */
9
  */
10
 Future getNewsList(params) async {
10
 Future getNewsList(params) async {
11
   return request('/news', options: Options(method: 'GET'),queryParameters: params)
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
   return request(
21
   return request(
24
     '/news/$id',
22
     '/news/$id',
25
     options: Options(method: 'GET'),
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 View File

1
 import 'package:dio/dio.dart';
1
 import 'package:dio/dio.dart';
2
 import 'package:farmer_client/utils/Request.dart';
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
  * @param {*} data
7
  * @param {*} data
10
 Future getOrderList(params) async {
10
 Future getOrderList(params) async {
11
   return request('/order',
11
   return request('/order',
12
           options: Options(method: 'GET'), queryParameters: params)
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
   return request(
22
   return request(
25
     '/order/$id',
23
     '/order/$id',
26
     options: Options(method: 'GET'),
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
 
33
 
38
 Future generateOrder(item) async {
34
 Future generateOrder(item) async {
39
   return request('/order', options: Options(method: 'POST'), data: item)
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
  */
43
  */
50
 Future orderDelete(String id) async {
44
 Future orderDelete(String id) async {
51
   return request('/order/$id', options: Options(method: 'DELETE'))
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
  */
53
  */
62
 Future orderRefund(String id) async {
54
 Future orderRefund(String id) async {
63
   return request('/order/$id/refund', options: Options(method: 'PUT'))
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
   return request('/evaluation',
66
   return request('/evaluation',
77
           options: Options(method: 'POST'),
67
           options: Options(method: 'POST'),
78
           data: {'orderId': orderId, 'score': score, 'content': content})
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 View File

1
 import 'package:dio/dio.dart';
1
 import 'package:dio/dio.dart';
2
 import 'package:farmer_client/utils/Request.dart';
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 View File

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 View File

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