李志伟 3 年前
父节点
当前提交
40e1cb0633
共有 3 个文件被更改,包括 28 次插入39 次删除
  1. 1
    4
      lib/pages/home/index.dart
  2. 22
    32
      lib/services/homeAPI.dart
  3. 5
    3
      lib/utils/Request.dart

+ 1
- 4
lib/pages/home/index.dart 查看文件

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

+ 22
- 32
lib/services/homeAPI.dart 查看文件

@@ -1,63 +1,53 @@
1
-
2
-
3 1
 import 'package:dio/dio.dart';
4 2
 import 'package:farmer_client/utils/Request.dart';
5 3
 import 'package:fluttertoast/fluttertoast.dart';
6 4
 
7
-
8
-
9 5
 /**
10 6
  * banner轮播图
11 7
  * @param {*} data
12 8
  * @returns
13 9
  */
14
-Future getHomeBanner(String position)async{
15
-  return request('/banner',options: Options(method: 'GET'),data: { 'position': position}).catchError((error) =>
16
-  { Fluttertoast.showToast(
17
-      msg: error.error['message']
18
-  ),});
19
-  
10
+Future getHomeBanner(String position) async {
11
+  return request('/banner',
12
+          options: Options(method: 'GET'), data: {'position': position})
13
+      .catchError((error) => {
14
+            Fluttertoast.showToast(msg: error.error['message']),
15
+          });
20 16
 }
21 17
 
22
-
23
-
24 18
 /**
25 19
  * 农机列表
26 20
  * @param {*} data
27 21
  * @returns
28 22
  */
29
-Future getMachinery(String location)async{
30
-  return request('/machinery',options: Options(method: 'GET'),queryParameters: { 'location': location}).catchError((error) =>
31
-  { Fluttertoast.showToast(
32
-      msg: error.error['message']
33
-  ),});
34
-
23
+Future getMachinery(String location) async {
24
+  return request('/machinery', options: Options(method: 'GET'), queryParameters: {
25
+    'location': location
26
+  }).catchError((error) => {
27
+        Fluttertoast.showToast(msg: error.error['message']),
28
+      });
35 29
 }
36 30
 
37
-
38
-
39 31
 /**
40 32
  * 农机详情
41 33
  * @param {*} data
42 34
  * @returns
43 35
  */
44
-Future getMachineryInfo(String id,String location ,bool attached)async{
45
-  return request('/machinery-summary',options: Options(method: 'GET'),queryParameters: { 'id': id},data: {'location': location,'attached': attached}).catchError((error) =>
46
-  { Fluttertoast.showToast(
47
-      msg: error.error['message']
48
-  ),});
49
-
36
+Future getMachineryInfo(String id, String location, bool attached) async {
37
+  return request('/machinery-summary',
38
+          options: Options(method: 'GET'),
39
+          queryParameters: {'id': id},
40
+          data: {'location': location, 'attached': attached})
41
+      .catchError((error) => {
42
+            Fluttertoast.showToast(msg: error.error['message']),
43
+          });
50 44
 }
51 45
 
52
-
53 46
 /**
54 47
  * 农机分类Tab列查询
55 48
  * @param {*} data
56 49
  * @returns
57 50
  */
58
-Future getMachineryType()async{
59
-  return request('/machinery-type',options: Options(method: 'GET'));
51
+Future getMachineryType() async {
52
+  return request('/machinery-type', options: Options(method: 'GET'));
60 53
 }
61
-
62
-
63
-

+ 5
- 3
lib/utils/Request.dart 查看文件

@@ -37,7 +37,7 @@ Dio createRequest() {
37 37
   var dio = Dio(options);
38 38
   dio.interceptors.add(InterceptorsWrapper(onRequest: (options, handler) {
39 39
     // Do something before request is sent
40
-    options.headers['Authorization'] =  GetStorage().read("token");
40
+    options.headers['Authorization'] = GetStorage().read("token");
41 41
     return handler.next(options); //continue
42 42
     // If you want to resolve the request with some custom data,
43 43
     // you can resolve a `Response` object eg: `handler.resolve(response)`.
@@ -59,7 +59,10 @@ Dio createRequest() {
59 59
 
60 60
       return handler.next(response);
61 61
     } else {
62
-      DioError error = DioError(requestOptions: response.requestOptions, error: response.data, response: response);
62
+      DioError error = DioError(
63
+          requestOptions: response.requestOptions,
64
+          error: response.data,
65
+          response: response);
63 66
       return handler.reject(error);
64 67
     }
65 68
   }, onError: (DioError e, handler) {
@@ -81,7 +84,6 @@ Future request(String path,
81 84
     Options? options,
82 85
     ProgressCallback? onSendProgress,
83 86
     ProgressCallback? onReceiveProgress}) async {
84
-
85 87
   var resp = await instance.request(path,
86 88
       data: data,
87 89
       queryParameters: queryParameters,