李志伟 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
 import 'dart:io';
2
 import 'dart:io';
3
 
3
 
4
 import 'package:amap_flutter_location/amap_flutter_location.dart';
4
 import 'package:amap_flutter_location/amap_flutter_location.dart';
5
+import 'package:get_storage/get_storage.dart';
5
 import 'package:worker_client/services/user.dart';
6
 import 'package:worker_client/services/user.dart';
6
 import '/models/entities/person.dart';
7
 import '/models/entities/person.dart';
7
 import '/widgets/Modal.dart';
8
 import '/widgets/Modal.dart';
11
 class AppController extends GetxController {
12
 class AppController extends GetxController {
12
   // 有了这句, 可以直接 AppController.t 调用
13
   // 有了这句, 可以直接 AppController.t 调用
13
   static AppController t = Get.find();
14
   static AppController t = Get.find();
14
-
15
+  GetStorage box = GetStorage();
15
   final user = Rx<Person>(Person());
16
   final user = Rx<Person>(Person());
16
   final location = Rxn<Map<String, Object>>();
17
   final location = Rxn<Map<String, Object>>();
17
   final testInt = 1.obs;
18
   final testInt = 1.obs;
35
   @override
36
   @override
36
   void onInit() {
37
   void onInit() {
37
     super.onInit();
38
     super.onInit();
38
-
39
     //尝试获取 location
39
     //尝试获取 location
40
     requireLocation(onLocationChange).then((loc) {
40
     requireLocation(onLocationChange).then((loc) {
41
       _location = loc;
41
       _location = loc;
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
   @override
62
   @override

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

85
             userInfo(Person.fromJson(res['person']));
85
             userInfo(Person.fromJson(res['person']));
86
             Fluttertoast.showToast(msg: '登录成功!');
86
             Fluttertoast.showToast(msg: '登录成功!');
87
             Get.offNamed('/home');
87
             Get.offNamed('/home');
88
-            // print(userInfo);
89
           }).catchError((err) {
88
           }).catchError((err) {
90
-            print(err);
91
             Fluttertoast.showToast(msg: err);
89
             Fluttertoast.showToast(msg: err);
92
           });
90
           });
93
         } else {
91
         } else {

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

1
+import 'dart:math';
2
+
1
 import 'package:carousel_slider/carousel_slider.dart';
3
 import 'package:carousel_slider/carousel_slider.dart';
2
 import 'package:flutter/material.dart';
4
 import 'package:flutter/material.dart';
3
 import 'package:flutter_screenutil/flutter_screenutil.dart';
5
 import 'package:flutter_screenutil/flutter_screenutil.dart';
127
                               itemCount: 1,
129
                               itemCount: 1,
128
                               itemBuilder:
130
                               itemBuilder:
129
                                   (BuildContext context, int position) {
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
                                 return Obx(() {
141
                                 return Obx(() {
135
                                   if (jobList.value != []) {
142
                                   if (jobList.value != []) {
136
                                     return Column(
143
                                     return Column(

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

38
 
38
 
39
   @override
39
   @override
40
   Widget builder(BuildContext context) {
40
   Widget builder(BuildContext context) {
41
-    print(store.user);
42
-
43
     return Container(
41
     return Container(
44
       decoration: const BoxDecoration(color: Colors.white),
42
       decoration: const BoxDecoration(color: Colors.white),
45
       child: ListView(
43
       child: ListView(
46
         children: [
44
         children: [
47
           Stack(
45
           Stack(
48
             children: [
46
             children: [
49
-              Obx(()=>
50
               Positioned(
47
               Positioned(
51
                 top: 0,
48
                 top: 0,
52
                 child: Container(
49
                 child: Container(
64
                       Container(
61
                       Container(
65
                         margin: EdgeInsets.fromLTRB(40.w, 0, 10.w, 0),
62
                         margin: EdgeInsets.fromLTRB(40.w, 0, 10.w, 0),
66
                         child: store.user().avatar != null
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
                             : Image.asset(
75
                             : Image.asset(
73
                                 'images/main/defaultAvatar.png',
76
                                 'images/main/defaultAvatar.png',
80
                         crossAxisAlignment: CrossAxisAlignment.start,
83
                         crossAxisAlignment: CrossAxisAlignment.start,
81
                         children: [
84
                         children: [
82
                           Text(
85
                           Text(
83
-                            store.user().nickName != null?store.user().nickName.toString():'',
86
+                            store.user().nickName != null
87
+                                ? store.user().nickName.toString()
88
+                                : '',
84
                             style: TextStyle(
89
                             style: TextStyle(
85
                                 color: Colors.white,
90
                                 color: Colors.white,
86
                                 fontWeight: FontWeight.w500,
91
                                 fontWeight: FontWeight.w500,
96
                           Container(
101
                           Container(
97
                             margin: EdgeInsets.fromLTRB(0, 19.h, 0, 0),
102
                             margin: EdgeInsets.fromLTRB(0, 19.h, 0, 0),
98
                             child: Text(
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
                               style: TextStyle(
107
                               style: TextStyle(
102
                                   color: Colors.white,
108
                                   color: Colors.white,
103
                                   fontWeight: FontWeight.w500,
109
                                   fontWeight: FontWeight.w500,
117
                   ),
123
                   ),
118
                 ),
124
                 ),
119
               ),
125
               ),
120
-              ),
121
               Positioned(
126
               Positioned(
122
                 right: 0,
127
                 right: 0,
123
                 top: 0,
128
                 top: 0,
124
                 child: Container(
129
                 child: Container(
125
                   decoration: const BoxDecoration(color: Color(0xb2000000)),
130
                   decoration: const BoxDecoration(color: Color(0xb2000000)),
126
                   child: Text(
131
                   child: Text(
127
-                    '该账号归${store.user().nickName!=null?store.user().nickName.toString():''}所属',
132
+                    '该账号归${store.user().nickName != null ? store.user().nickName.toString() : ''}所属',
128
                     style: TextStyle(color: Colors.white, fontSize: 12.sp),
133
                     style: TextStyle(color: Colors.white, fontSize: 12.sp),
129
                   ),
134
                   ),
130
                 ),
135
                 ),

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

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