瀏覽代碼

LoginStyle

[baozhangchao] 3 年之前
父節點
當前提交
4eb2cf3034
共有 8 個檔案被更改,包括 67 行新增90 行删除
  1. 0
    14
      lib/main.dart
  2. 1
    0
      lib/models/Store.dart
  3. 1
    1
      lib/models/app.dart
  4. 1
    0
      lib/pages/home.dart
  5. 55
    65
      lib/pages/login/login.dart
  6. 0
    1
      lib/pages/splash/splash.dart
  7. 6
    6
      lib/services/user.dart
  8. 3
    3
      pubspec.lock

+ 0
- 14
lib/main.dart 查看文件

@@ -1,12 +1,5 @@
1 1
 
2
-<<<<<<< HEAD
3
-import 'package:farmer_client/models/Store.dart';
4
-import 'package:farmer_client/pages/home.dart';
5
-import 'package:farmer_client/pages/login/login.dart';
6 2
 import 'package:farmer_client/widgets/CarsCard.dart';
7
-import 'package:farmer_client/widgets/OrderInfoCard.dart';
8
-=======
9
->>>>>>> aab895cc95471d4dfd7cb90d05a35ccceb52c4e0
10 3
 import 'package:flutter/material.dart';
11 4
 import 'package:get/get.dart';
12 5
 import 'package:get_storage/get_storage.dart';
@@ -39,16 +32,9 @@ class MyApp extends StatelessWidget {
39 32
         return GetMaterialApp(
40 33
           initialRoute: '/splash',
41 34
           defaultTransition: Transition.native,
42
-<<<<<<< HEAD
43
-          getPages: [
44
-            // GetPage(name: '/home', page: () => OrderPage() ),
45
-            GetPage(name: '/home', page: () => box.hasData('token') ? Home() : MyRouteLogin()),
46
-          ],
47
-=======
48 35
           routingCallback: routingCallback,
49 36
           initialBinding: AppBindings(),
50 37
           getPages: pages,
51
->>>>>>> aab895cc95471d4dfd7cb90d05a35ccceb52c4e0
52 38
         );
53 39
       },
54 40
     );

+ 1
- 0
lib/models/Store.dart 查看文件

@@ -0,0 +1 @@
1
+// TODO Implement this library.

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

@@ -11,7 +11,7 @@ class AppController extends GetxController {
11 11
   // 有了这句, 可以直接 AppController.t 调用
12 12
   static AppController t = Get.find();
13 13
 
14
-  final user = Person().obs;
14
+  final user = Rx<Person>(Person());
15 15
   final location = Rxn<LocationData>();
16 16
   final testInt = 1.obs;
17 17
 

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

@@ -0,0 +1 @@
1
+// TODO Implement this library.

+ 55
- 65
lib/pages/login/login.dart 查看文件

@@ -7,6 +7,7 @@ import 'package:flutter/material.dart';
7 7
 import 'package:flutter_screenutil/flutter_screenutil.dart';
8 8
 import 'package:get/get.dart';
9 9
 
10
+import '../../models/entities/person.dart';
10 11
 import '../../services/user.dart';
11 12
 import '../../widgets/Cell.dart';
12 13
 
@@ -37,6 +38,35 @@ class MyRouteLogin extends StatefulWidget {
37 38
 }
38 39
 
39 40
 class _RouteLogin extends State<MyRouteLogin> {
41
+
42
+var  userInfo= AppController.t.user;
43
+
44
+bool isButtonEnable = true; //按钮状态  是否可点击
45
+String buttonText = '发送验证码'; //初始文本
46
+int count = 60; //初始倒计时时间
47
+var timer; //倒计时的计时器
48
+TextEditingController mController = TextEditingController();
49
+
50
+//获取验证码
51
+void _initTimer() {
52
+  timer = Timer.periodic(Duration(seconds: 1), (Timer timer) {
53
+    count--;
54
+    setState(() {
55
+      if (count == 0) {
56
+        timer.cancel(); //倒计时结束取消定时器
57
+        isButtonEnable = true; //按钮可点击
58
+        count = 60; //重置时间
59
+        buttonText = '发送验证码'; //重置按钮文本
60
+      } else {
61
+        buttonText = '重新发送($count)'; //更新文本内容
62
+      }
63
+    });
64
+  });
65
+}
66
+
67
+
68
+
69
+
40 70
   @override
41 71
   void initState() {
42 72
     super.initState();
@@ -47,28 +77,6 @@ class _RouteLogin extends State<MyRouteLogin> {
47 77
     print(location);
48 78
   }
49 79
 
50
-  bool isButtonEnable = true; //按钮状态  是否可点击
51
-  String buttonText = '发送验证码'; //初始文本
52
-  int count = 60; //初始倒计时时间
53
-  var timer; //倒计时的计时器
54
-  TextEditingController mController = TextEditingController();
55
-
56
-  void _initTimer() {
57
-    timer = Timer.periodic(Duration(seconds: 1), (Timer timer) {
58
-      count--;
59
-      setState(() {
60
-        if (count == 0) {
61
-          timer.cancel(); //倒计时结束取消定时器
62
-          isButtonEnable = true; //按钮可点击
63
-          count = 60; //重置时间
64
-          buttonText = '发送验证码'; //重置按钮文本
65
-        } else {
66
-          buttonText = '重新发送($count)'; //更新文本内容
67
-        }
68
-      });
69
-    });
70
-  }
71
-
72 80
   @override
73 81
   void dispose() {
74 82
     timer?.cancel(); //销毁计时器
@@ -82,6 +90,9 @@ class _RouteLogin extends State<MyRouteLogin> {
82 90
 // -------------逻辑分割-------------------------------------------
83 91
   var handlePhones = '';
84 92
   var handleCodes = '';
93
+  var userContent = {'phones': '', 'code': ''};
94
+  bool _newValue = false;
95
+
85 96
 
86 97
   void _handlePhone(e) => {
87 98
         setState(() => {handlePhones = e})
@@ -91,19 +102,9 @@ class _RouteLogin extends State<MyRouteLogin> {
91 102
         setState(() => {handleCodes = e})
92 103
       };
93 104
 
94
-  var userContent = {'phones': '', 'code': ''};
95 105
 
96
-  void phoneUser() => {
97
-        setState(() {
98
-          userContent['phones'] = handlePhones;
99
-          userContent['code'] = handleCodes;
100
-        }),
101
-        print('我输入的信息:${userContent},手机号:${userContent['phones']}')
102
-      };
103
-
104
-  bool _checkValue = false;
105
-  bool _newValue = false;
106 106
 
107
+// 获取验证码
107 108
   void _buttonClickListen() {
108 109
     setState(() {
109 110
       if (isButtonEnable) {
@@ -113,13 +114,28 @@ class _RouteLogin extends State<MyRouteLogin> {
113 114
           getSMSCaptch(handlePhones);
114 115
         } else {
115 116
           Fluttertoast.showToast(msg: '请正确输入手机号!');
116
-
117 117
         }
118
-
119 118
         print('获取验证码按钮222222');
120 119
       }
121 120
     });
122 121
   }
122
+//登陆按钮
123
+  void _handelSubmit(){
124
+    if(handleCodes==''||handlePhones==''){
125
+      Fluttertoast.showToast(msg: '请输入验证码或手机号!');
126
+    }else{
127
+      if(_newValue){
128
+        print('已同意协议');
129
+        userLogin(handlePhones,handleCodes).then((value) {
130
+          userInfo(Person.fromJson(value.date.person));
131
+          Get.back();
132
+
133
+        });
134
+      }else{
135
+        Fluttertoast.showToast(msg: '请阅读并同意相关隐私政策!');
136
+      }
137
+    }
138
+  }
123 139
 
124 140
   @override
125 141
   Widget build(BuildContext context) {
@@ -153,7 +169,6 @@ class _RouteLogin extends State<MyRouteLogin> {
153 169
                   fontSize: 35,
154 170
                 ),
155 171
               ),
156
-
157 172
               Cell(
158 173
                   // margin: EdgeInsets.symmetric(horizontal: 13.w),
159 174
                   margin: const EdgeInsets.fromLTRB(13, 43, 10, 0),
@@ -187,21 +202,7 @@ class _RouteLogin extends State<MyRouteLogin> {
187 202
                     child: ElevatedButton(
188 203
                       onPressed: () => {
189 204
                         setState(() {
190
-                          // _buttonClickListen();
191
-                          setState(() {
192
-                            if (isButtonEnable) {
193
-                              if (handlePhones != '') {
194
-                                isButtonEnable = false; //按钮状态标记
195
-                                _initTimer();
196
-                                getSMSCaptch(handlePhones);
197
-                              } else {
198
-                                Fluttertoast.showToast(msg: '请正确输入手机号!');
199
-                              }
200
-
201
-                              print('获取验证码按钮222222');
202
-                            }
203
-                          });
204
-
205
+                          _buttonClickListen();
205 206
                         })
206 207
                       },
207 208
                       child: Text(
@@ -222,8 +223,6 @@ class _RouteLogin extends State<MyRouteLogin> {
222 223
                       ),
223 224
                     ),
224 225
                   )),
225
-//          --------------FractionalOffset API--------------
226
-
227 226
               Cell(
228 227
                 // margin: EdgeInsets.symmetric(horizontal: 13.w),
229 228
                 margin: const EdgeInsets.fromLTRB(13, 16, 10, 0),
@@ -264,16 +263,7 @@ class _RouteLogin extends State<MyRouteLogin> {
264 263
                   height: 49.h,
265 264
                   child: ElevatedButton(
266 265
                     onPressed: () {
267
-                      if(handleCodes==''||handlePhones==''){
268
-                        Fluttertoast.showToast(msg: '请输入验证码或手机号!');
269
-                      }else{
270
-                        if(_newValue){
271
-                          print('已同意协议');
272
-                          userLogin(handlePhones,handleCodes);
273
-                        }else{
274
-                          Fluttertoast.showToast(msg: '请阅读并同意相关隐私政策!');
275
-                        }
276
-                      }
266
+                      _handelSubmit();
277 267
                     },
278 268
                     child: const Text(
279 269
                       "登陆",
@@ -310,7 +300,7 @@ class _RouteLogin extends State<MyRouteLogin> {
310 300
                           }),
311 301
                       RichText(
312 302
                         text: TextSpan(children: <InlineSpan>[
313
-                          TextSpan(
303
+                          const TextSpan(
314 304
                               text: '请认真查看',
315 305
                               style: TextStyle(color: Color(0xff2a2a2a))),
316 306
                           TextSpan(
@@ -322,7 +312,7 @@ class _RouteLogin extends State<MyRouteLogin> {
322 312
                                     print('阅读已同意!!!');
323 313
                                   },
324 314
                           ),
325
-                          TextSpan(
315
+                          const TextSpan(
326 316
                               text: '确认之后选择此项',
327 317
                               style: TextStyle(color: Color(0xff2a2a2a))),
328 318
                         ]),

+ 0
- 1
lib/pages/splash/splash.dart 查看文件

@@ -9,7 +9,6 @@ class SplashScreen extends StatelessWidget {
9 9
   handleOnFinish () {
10 10
     Get.off(Home(), routeName: '/');
11 11
   }
12
-
13 12
   @override
14 13
   Widget build(BuildContext context) {
15 14
     return countdown(3, handleOnFinish);

+ 6
- 6
lib/services/user.dart 查看文件

@@ -18,15 +18,15 @@ Future getSMSCaptch(String phone) async {
18 18
   });
19 19
 }
20 20
 
21
-<<<<<<< HEAD
22
-
23 21
 //登陆
24 22
 Future userLogin(String userName,String password) async {
25
-  return request('/login', options: Options(method: 'POST'), data: { 'userName': userName,'password':password }, ).catchError((error)=>{ Fluttertoast.showToast(
26
-  msg: error.error['message']
23
+  return request('/login', options: Options(method: 'POST'),
24
+    data: { 'userName': userName, 'password': password},).catchError((error) =>
25
+  { Fluttertoast.showToast(
26
+      msg: error.error['message']
27 27
   ),});
28
-=======
28
+}
29
+
29 30
 Future getCurrent() async {
30 31
   return request('/person/current');
31
->>>>>>> aab895cc95471d4dfd7cb90d05a35ccceb52c4e0
32 32
 }

+ 3
- 3
pubspec.lock 查看文件

@@ -237,21 +237,21 @@ packages:
237 237
     dependency: "direct main"
238 238
     description:
239 239
       name: location
240
-      url: "https://pub.flutter-io.cn"
240
+      url: "https://pub.dartlang.org"
241 241
     source: hosted
242 242
     version: "4.3.0"
243 243
   location_platform_interface:
244 244
     dependency: transitive
245 245
     description:
246 246
       name: location_platform_interface
247
-      url: "https://pub.flutter-io.cn"
247
+      url: "https://pub.dartlang.org"
248 248
     source: hosted
249 249
     version: "2.3.0"
250 250
   location_web:
251 251
     dependency: transitive
252 252
     description:
253 253
       name: location_web
254
-      url: "https://pub.flutter-io.cn"
254
+      url: "https://pub.dartlang.org"
255 255
     source: hosted
256 256
     version: "3.1.1"
257 257
   logging: