李志伟 3 年前
父节点
当前提交
401a34c499
共有 5 个文件被更改,包括 45 次插入34 次删除
  1. 10
    8
      lib/models/app.dart
  2. 0
    2
      lib/pages/Login/index.dart
  3. 11
    4
      lib/pages/home/index.dart
  4. 17
    12
      lib/pages/main/index.dart
  5. 7
    8
      lib/widgets/LoadMore.dart

+ 10
- 8
lib/models/app.dart 查看文件

@@ -2,6 +2,7 @@
2 2
 import 'dart:io';
3 3
 
4 4
 import 'package:amap_flutter_location/amap_flutter_location.dart';
5
+import 'package:get_storage/get_storage.dart';
5 6
 import 'package:worker_client/services/user.dart';
6 7
 import '/models/entities/person.dart';
7 8
 import '/widgets/Modal.dart';
@@ -11,7 +12,7 @@ import '../utils/location.dart';
11 12
 class AppController extends GetxController {
12 13
   // 有了这句, 可以直接 AppController.t 调用
13 14
   static AppController t = Get.find();
14
-
15
+  GetStorage box = GetStorage();
15 16
   final user = Rx<Person>(Person());
16 17
   final location = Rxn<Map<String, Object>>();
17 18
   final testInt = 1.obs;
@@ -35,7 +36,6 @@ class AppController extends GetxController {
35 36
   @override
36 37
   void onInit() {
37 38
     super.onInit();
38
-
39 39
     //尝试获取 location
40 40
     requireLocation(onLocationChange).then((loc) {
41 41
       _location = loc;
@@ -49,12 +49,14 @@ class AppController extends GetxController {
49 49
       );
50 50
     });
51 51
 
52
-    // // 尝试获取一次人员信息
53
-    getCurrent().then((person) {
54
-      user(Person.fromJson(person));
55
-    }).catchError((e) {
56
-      print(e);
57
-    });
52
+    if(box.read('token')!=null) {
53
+      // 尝试获取一次人员信息
54
+      getCurrent().then((person) {
55
+        user(Person.fromJson(person));
56
+      }).catchError((e) {
57
+        print(e);
58
+      });
59
+    }
58 60
   }
59 61
 
60 62
   @override

+ 0
- 2
lib/pages/Login/index.dart 查看文件

@@ -85,9 +85,7 @@ class _Login extends State<Login> {
85 85
             userInfo(Person.fromJson(res['person']));
86 86
             Fluttertoast.showToast(msg: '登录成功!');
87 87
             Get.offNamed('/home');
88
-            // print(userInfo);
89 88
           }).catchError((err) {
90
-            print(err);
91 89
             Fluttertoast.showToast(msg: err);
92 90
           });
93 91
         } else {

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

@@ -1,3 +1,5 @@
1
+import 'dart:math';
2
+
1 3
 import 'package:carousel_slider/carousel_slider.dart';
2 4
 import 'package:flutter/material.dart';
3 5
 import 'package:flutter_screenutil/flutter_screenutil.dart';
@@ -127,10 +129,15 @@ class Home extends BasicPage {
127 129
                               itemCount: 1,
128 130
                               itemBuilder:
129 131
                                   (BuildContext context, int position) {
130
-                                jobList([
131
-                                  ...jobList.value,
132
-                                  ...GetList(data.records)
133
-                                ]);
132
+                                if (jobList.value.isNotEmpty &&
133
+                                    jobList.value[0].jobId !=
134
+                                        GetList(data.records)[0].jobId) {
135
+                                  jobList([
136
+                                    ...jobList.value,
137
+                                    ...GetList(data.records)
138
+                                  ]);
139
+                                }
140
+
134 141
                                 return Obx(() {
135 142
                                   if (jobList.value != []) {
136 143
                                     return Column(

+ 17
- 12
lib/pages/main/index.dart 查看文件

@@ -38,15 +38,12 @@ class Main extends BasicPage {
38 38
 
39 39
   @override
40 40
   Widget builder(BuildContext context) {
41
-    print(store.user);
42
-
43 41
     return Container(
44 42
       decoration: const BoxDecoration(color: Colors.white),
45 43
       child: ListView(
46 44
         children: [
47 45
           Stack(
48 46
             children: [
49
-              Obx(()=>
50 47
               Positioned(
51 48
                 top: 0,
52 49
                 child: Container(
@@ -64,10 +61,16 @@ class Main extends BasicPage {
64 61
                       Container(
65 62
                         margin: EdgeInsets.fromLTRB(40.w, 0, 10.w, 0),
66 63
                         child: store.user().avatar != null
67
-                            ? Image.network(
68
-                                store.user().avatar.toString(),
69
-                                width: 63.w,
70
-                                height: 63.w,
64
+                            ? Container(
65
+                                clipBehavior: Clip.hardEdge,
66
+                                decoration: BoxDecoration(
67
+                                    borderRadius: BorderRadius.all(
68
+                                        Radius.circular(31.5.w))),
69
+                                child: Image.network(
70
+                                  store.user().avatar.toString(),
71
+                                  width: 63.w,
72
+                                  height: 63.w,
73
+                                ),
71 74
                               )
72 75
                             : Image.asset(
73 76
                                 'images/main/defaultAvatar.png',
@@ -80,7 +83,9 @@ class Main extends BasicPage {
80 83
                         crossAxisAlignment: CrossAxisAlignment.start,
81 84
                         children: [
82 85
                           Text(
83
-                            store.user().nickName != null?store.user().nickName.toString():'',
86
+                            store.user().nickName != null
87
+                                ? store.user().nickName.toString()
88
+                                : '',
84 89
                             style: TextStyle(
85 90
                                 color: Colors.white,
86 91
                                 fontWeight: FontWeight.w500,
@@ -96,8 +101,9 @@ class Main extends BasicPage {
96 101
                           Container(
97 102
                             margin: EdgeInsets.fromLTRB(0, 19.h, 0, 0),
98 103
                             child: Text(
99
-                                store.user().nickName != null?
100
-                              store.user().phone.toString():'',
104
+                              store.user().nickName != null
105
+                                  ? store.user().phone.toString()
106
+                                  : '',
101 107
                               style: TextStyle(
102 108
                                   color: Colors.white,
103 109
                                   fontWeight: FontWeight.w500,
@@ -117,14 +123,13 @@ class Main extends BasicPage {
117 123
                   ),
118 124
                 ),
119 125
               ),
120
-              ),
121 126
               Positioned(
122 127
                 right: 0,
123 128
                 top: 0,
124 129
                 child: Container(
125 130
                   decoration: const BoxDecoration(color: Color(0xb2000000)),
126 131
                   child: Text(
127
-                    '该账号归${store.user().nickName!=null?store.user().nickName.toString():''}所属',
132
+                    '该账号归${store.user().nickName != null ? store.user().nickName.toString() : ''}所属',
128 133
                     style: TextStyle(color: Colors.white, fontSize: 12.sp),
129 134
                   ),
130 135
                 ),

+ 7
- 8
lib/widgets/LoadMore.dart 查看文件

@@ -1,4 +1,3 @@
1
-
2 1
 import 'package:flutter/widgets.dart';
3 2
 import '/models/entities/PagedResult.dart';
4 3
 
@@ -8,20 +7,20 @@ class LoadMore extends StatefulWidget {
8 7
     required this.builder,
9 8
     required this.fetch,
10 9
     this.onError,
11
-  }): super(key: key);
10
+  }) : super(key: key);
12 11
 
13 12
   Future Function(Map param) fetch;
14 13
   Function? onError;
15 14
 
16 15
   Widget Function({
17
-  required BuildContext context,
18
-  required ScrollController scrollController,
19
-  required PagedResult data,
20
-  required bool haveMore,
16
+    required BuildContext context,
17
+    required ScrollController scrollController,
18
+    required PagedResult data,
19
+    required bool haveMore,
21 20
   }) builder;
22 21
 
23 22
   @override
24
-  State<StatefulWidget> createState () => _LoadMoreState();
23
+  State<StatefulWidget> createState() => _LoadMoreState();
25 24
 }
26 25
 
27 26
 class _LoadMoreState extends State<LoadMore> {
@@ -53,7 +52,7 @@ class _LoadMoreState extends State<LoadMore> {
53 52
   Future fetchData() {
54 53
     final pageNum = result.current + 1;
55 54
     final pageSize = result.size == 0 ? 10 : result.size;
56
-    Map<String, dynamic> params = { "pageNum": pageNum, "pageSize": pageSize };
55
+    Map<String, dynamic> params = {"pageNum": pageNum, "pageSize": pageSize};
57 56
     return Future.value(widget.fetch(params).then((res) {
58 57
       setState(() {
59 58
         result = PagedResult.fromJson(res);