[baozhangchao] 3 年之前
父節點
當前提交
3f8edf1326

二進制
images/phoneCode.png 查看文件


+ 2
- 1
lib/main.dart 查看文件

@@ -9,6 +9,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
9 9
 import 'components/UI/DefaultButton.dart';
10 10
 
11 11
 void main() {
12
+  Store().init();
12 13
   runApp(const MyApp());
13 14
 }
14 15
 
@@ -18,7 +19,6 @@ class MyApp extends StatelessWidget {
18 19
   // This widget is the root of your application.
19 20
   @override
20 21
   Widget build(BuildContext context) {
21
-    Store().init();
22 22
 
23 23
     return MaterialApp(
24 24
       title: 'Flutter Demo',
@@ -35,6 +35,7 @@ class MyApp extends StatelessWidget {
35 35
         primarySwatch: Colors.blue,
36 36
       ),
37 37
       home: const MyHomePage(title: 'Flutter Demo Home Page'),
38
+        // IndexPage()
38 39
     );
39 40
   }
40 41
 }

+ 11
- 0
lib/pages/TabBar/Information_page.dart 查看文件

@@ -0,0 +1,11 @@
1
+import 'package:flutter/material.dart';
2
+
3
+class InformationPage extends StatelessWidget {
4
+  @override
5
+  Widget build(BuildContext context) {
6
+    // TODO: implement build
7
+    return Scaffold(
8
+      body: Center(child: Text('资讯')),
9
+    );
10
+  }
11
+}

+ 11
- 0
lib/pages/TabBar/Mine_page.dart 查看文件

@@ -0,0 +1,11 @@
1
+import 'package:flutter/material.dart';
2
+
3
+class MinePage extends StatelessWidget {
4
+  @override
5
+  Widget build(BuildContext context) {
6
+    // TODO: implement build
7
+    return Scaffold(
8
+      body: Center(child: Text('我的')),
9
+    );
10
+  }
11
+}

+ 11
- 0
lib/pages/TabBar/Orders_page.dart 查看文件

@@ -0,0 +1,11 @@
1
+import 'package:flutter/material.dart';
2
+
3
+class OrdersPage extends StatelessWidget {
4
+  @override
5
+  Widget build(BuildContext context) {
6
+    // TODO: implement build
7
+    return Scaffold(
8
+      body: Center(child: Text('订单')),
9
+    );
10
+  }
11
+}

+ 10
- 0
lib/pages/TabBar/home_page.dart 查看文件

@@ -0,0 +1,10 @@
1
+import 'package:flutter/material.dart';
2
+
3
+class HomePage extends StatelessWidget {
4
+  @override
5
+  Widget build(BuildContext context) {
6
+    return Scaffold(
7
+      body: Center(child: Text('首页')),
8
+    );
9
+  }
10
+}

+ 71
- 0
lib/pages/TabBar/index_page.dart 查看文件

@@ -0,0 +1,71 @@
1
+import 'package:flutter/material.dart';
2
+import 'package:flutter/cupertino.dart';
3
+import 'home_page.dart';
4
+import 'Information_page.dart';
5
+import 'Mine_page.dart';
6
+import 'Orders_page.dart';
7
+
8
+class IndexPage extends StatefulWidget {
9
+  _IndexPageState createState() => _IndexPageState();
10
+}
11
+
12
+class _IndexPageState extends State<IndexPage> {
13
+
14
+
15
+  final List<BottomNavigationBarItem> bottomTabs = [
16
+     BottomNavigationBarItem(
17
+      icon: Icon(CupertinoIcons.home),
18
+      title: Text('首页'),
19
+    ),
20
+     BottomNavigationBarItem(
21
+      icon: Icon(CupertinoIcons.search),
22
+      title: Text('资讯'),
23
+
24
+    ),
25
+     BottomNavigationBarItem(
26
+      icon: Icon(CupertinoIcons.shopping_cart),
27
+      title: Text('订单'),
28
+
29
+    ),
30
+     BottomNavigationBarItem(
31
+      icon: Icon(CupertinoIcons.profile_circled),
32
+      title: Text('我的'),
33
+    ),
34
+  ];
35
+
36
+  final List tabBodies = [
37
+    HomePage(),
38
+    InformationPage(),
39
+    OrdersPage(),
40
+    MinePage(),
41
+  ];
42
+
43
+  int currentIndex = 0;
44
+  var currentPage;
45
+
46
+  @override
47
+  void initState() {
48
+    super.initState();
49
+    currentPage = tabBodies[currentIndex];
50
+  }
51
+
52
+  @override
53
+  Widget build(BuildContext context) {
54
+    // TODO: implement build
55
+    return Scaffold(
56
+      backgroundColor: Color.fromRGBO(244, 245, 245, 1),
57
+      bottomNavigationBar: BottomNavigationBar(
58
+        type: BottomNavigationBarType.fixed,
59
+        currentIndex: currentIndex,
60
+        items: bottomTabs,
61
+        onTap: (index){
62
+          setState(() {
63
+            currentIndex = index;
64
+            currentPage = tabBodies[currentIndex];
65
+          });
66
+        },
67
+      ),
68
+      body: currentPage,
69
+    );
70
+  }
71
+}

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

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

+ 95
- 40
lib/pages/login/login.dart 查看文件

@@ -4,6 +4,7 @@ import 'package:farmer_client/components/UI/DefaultButton.dart';
4 4
 import 'package:flutter/material.dart';
5 5
 import 'package:flutter_screenutil/flutter_screenutil.dart';
6 6
 
7
+import '../../services/user.dart';
7 8
 import '../../widgets/Cell.dart';
8 9
 
9 10
 class MyRouteLogin extends StatefulWidget {
@@ -24,6 +25,7 @@ class _RouteLogin extends State<MyRouteLogin> {
24 25
         //当按钮可点击时
25 26
         isButtonEnable = false; //按钮状态标记
26 27
         _initTimer();
28
+        getSMSCaptch(handlePhones);
27 29
         return null; //返回null按钮禁止点击
28 30
       } else {
29 31
         //当按钮不可点击时
@@ -82,7 +84,7 @@ class _RouteLogin extends State<MyRouteLogin> {
82 84
   @override
83 85
   Widget build(BuildContext context) {
84 86
     return Container(
85
-        width: 12.w,
87
+
86 88
         decoration: const BoxDecoration(
87 89
           image: DecorationImage(
88 90
             image: AssetImage("images/icon_login.png"),
@@ -97,17 +99,18 @@ class _RouteLogin extends State<MyRouteLogin> {
97 99
               title: const Text('登陆'),
98 100
             ),
99 101
             body: Center(
100
-                child: Column(
101
-              crossAxisAlignment: CrossAxisAlignment.start,
102
+                child:  ListView(
103
+              // crossAxisAlignment: CrossAxisAlignment.start,
102 104
               children: <Widget>[
103
-                Text(
105
+
106
+                const Text(
104 107
                   '您好!',
105 108
                   style: TextStyle(
106 109
                     fontWeight: FontWeight.bold,
107 110
                     fontSize: 50,
108 111
                   ),
109 112
                 ),
110
-                Text(
113
+                const Text(
111 114
                   '欢迎进入农户端应用!',
112 115
                   style: TextStyle(
113 116
                     fontWeight: FontWeight.bold,
@@ -184,12 +187,15 @@ class _RouteLogin extends State<MyRouteLogin> {
184 187
                 //     )),
185 188
 
186 189
                 Cell(
187
-                  margin: EdgeInsets.symmetric(horizontal: 13.w),
190
+                  // margin: EdgeInsets.symmetric(horizontal: 13.w),
191
+                  margin: const EdgeInsets.fromLTRB(13, 43, 10,0 ),
188 192
                   header: Text(
189 193
                     "+86",
190
-                    style: TextStyle(fontSize: 19.sp),
194
+                    style: TextStyle(fontSize: 19.sp,),
191 195
                   ),
192 196
                   child: TextField(
197
+                    maxLength: 11,
198
+                      keyboardType: TextInputType.number,
193 199
                       style: TextStyle(
194 200
                         fontSize: 17.sp,
195 201
                       ),
@@ -198,13 +204,14 @@ class _RouteLogin extends State<MyRouteLogin> {
198 204
                         contentPadding:
199 205
                             EdgeInsets.symmetric(vertical: 8, horizontal: 16),
200 206
                         labelText: "请输入手机号码",
207
+                        counterText: '',//去掉计数
201 208
                         border: InputBorder.none,
202
-                        // border: OutlineInputBorder(
203
-                        //   // borderSide: BorderSide.none,
204
-                        //   // gapPadding: 0,
205
-                        // ),
206 209
                         floatingLabelBehavior: FloatingLabelBehavior.never,
207
-                      )),
210
+                      ),
211
+                      onChanged: (e) {
212
+                                _handlePhone(e);
213
+                              },
214
+                  ),
208 215
                   footer: ElevatedButton(
209 216
                     onPressed: () => {
210 217
                       setState(() {
@@ -227,38 +234,86 @@ class _RouteLogin extends State<MyRouteLogin> {
227 234
                                 BorderRadius.all(Radius.circular(10)))),
228 235
                   ),
229 236
                 ),
237
+//          --------------FractionalOffset API--------------
238
+//                 FractionalOffset(0.0, 0.0):顶部左边
239
+//                 FractionalOffset(0.5, 0.0):顶部中间
240
+//                 FractionalOffset(1.0, 0.0):顶部右边
241
+//                 FractionalOffset(0.0, 0.5):中部左边
242
+//                 FractionalOffset(0.5, 0.5):中部中间
243
+//                 FractionalOffset(1.0, 0.5):中部右边
244
+//                 FractionalOffset(0.0, 1.0):底部左边
245
+//                 FractionalOffset(0.5, 1.0):底部中间
246
+//                 FractionalOffset(1.0, 1.0):底部右边
230 247
 
231
-                TextField(
232
-                  keyboardType: TextInputType.number,
233
-                  cursorColor: Color(0xD4D4D4FF),
234
-                  decoration: const InputDecoration(
235
-                      hintText: "请输入验证码", prefixIcon: Icon(Icons.beenhere)),
236
-                  onChanged: (e) {
237
-                    _handleCode(e);
238
-                  },
239
-                ),
240
-                // 登录按钮
248
+                Cell(
249
+                  // margin: EdgeInsets.symmetric(horizontal: 13.w),
250
+                  margin: const EdgeInsets.fromLTRB(13, 16, 10,0 ),
241 251
 
242
-                Container(
243
-                  child: DefaultButton(
244
-                    margin:
245
-                        EdgeInsets.fromLTRB(0, 30.0, 0, 0), //可选配置,自定义控件中有默认配置
246
-                    text: "登陆",
247
-                    width: 200.0,
248
-                    height: 50.0,
249
-                    fontSize: 20.0,
250
-                    backColor: Color(0xffff703b),
251
-                    color: Colors.white,
252
-                    onPressed: () {
253
-                      Navigator.push(
254
-                        context,
255
-                        MaterialPageRoute(builder: (context) {
256
-                          return MyRouteLogin();
257
-                        }),
258
-                      );
252
+                  header:        Align(
253
+                    alignment: FractionalOffset(0.1, 0.5),
254
+                    child: Image.asset(
255
+                      'images/phoneCode.png',
256
+                      width: 20,
257
+                      height: 20,
258
+                    ),
259
+                  ),
260
+
261
+                  child: TextField(
262
+                    keyboardType: TextInputType.number,
263
+                    style: TextStyle(
264
+                      fontSize: 17.sp,
265
+
266
+                    ),
267
+                    decoration: const InputDecoration(
268
+                      isCollapsed: true,
269
+
270
+                      contentPadding:
271
+                      EdgeInsets.symmetric(vertical: 8, horizontal: 16),
272
+                      labelText: "请输入验证码",
273
+                      border: InputBorder.none,
274
+                      floatingLabelBehavior: FloatingLabelBehavior.never,
275
+                    ),
276
+                    onChanged: (e) {
277
+                      _handleCode(e);
259 278
                     },
260 279
                   ),
261
-                )
280
+
281
+                ),
282
+
283
+
284
+
285
+
286
+                // TextField(
287
+                //   style: TextStyle(
288
+                //     fontSize: 17.sp,
289
+                //   ),
290
+                //   keyboardType: TextInputType.number,
291
+                //   cursorColor: Color(0xD4D4D4FF),
292
+                //   decoration: const InputDecoration(
293
+                //       contentPadding:
294
+                //       EdgeInsets.symmetric(vertical: 8, horizontal: 16),
295
+                //       labelText: "请输入验证码",
296
+                //       prefixIcon: Icon(Icons.beenhere)),
297
+                //   onChanged: (e) {
298
+                //     _handleCode(e);
299
+                //   },
300
+                // ),
301
+                // 登录按钮
302
+                 Center(
303
+                    child: DefaultButton(
304
+                      margin: const EdgeInsets.fromLTRB(0, 30.0, 0, 0), //可选配置,自定义控件中有默认配置
305
+                      text: "登陆",
306
+                      width: 90.0,
307
+                      height: 50.0,
308
+                      fontSize: 20.0,
309
+                      backColor: const Color(0xffff703b),
310
+                      color: Colors.white,
311
+                      onPressed: () {
312
+                      },
313
+                    ),
314
+                  ) ,
315
+
316
+
262 317
               ],
263 318
             ))));
264 319
   }

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

@@ -1,8 +1,20 @@
1 1
 
2
+
2 3
 import 'package:dio/dio.dart';
3 4
 import 'package:farmer_client/utils/Request.dart';
4
-import 'package:flutter/foundation.dart';
5
+import 'package:fluttertoast/fluttertoast.dart';
6
+
5 7
 
6 8
 Future getSMSCaptch(String phone) async {
7
-  return request('/sms-captcha', options: Options(method: 'POST'), queryParameters: { 'phone': phone });
9
+  return request('/sms-captcha', options: Options(method: 'POST'), queryParameters: { 'phone': phone }).catchError((error) {
10
+    // var e = error.error ;
11
+    // var message = e['message'];
12
+    Fluttertoast.showToast(
13
+      msg: error.error['message']
14
+    );
15
+  }).then((value) {
16
+    Fluttertoast.showToast(
17
+        msg: '验证码发送成功!'
18
+    );
19
+  });
8 20
 }

+ 2
- 1
lib/utils/Request.dart 查看文件

@@ -48,7 +48,8 @@ Dio createRequest() {
48 48
       response.data = resp['data'];
49 49
       return handler.next(response);
50 50
     } else {
51
-      return handler.reject(response.data);
51
+      DioError error = DioError(requestOptions: response.requestOptions, error: response.data, response: response);
52
+      return handler.reject(error);
52 53
     }
53 54
   }, onError: (DioError e, handler) {
54 55
     // Do something with response error

+ 20
- 0
pubspec.lock 查看文件

@@ -158,6 +158,18 @@ packages:
158 158
     description: flutter
159 159
     source: sdk
160 160
     version: "0.0.0"
161
+  flutter_web_plugins:
162
+    dependency: transitive
163
+    description: flutter
164
+    source: sdk
165
+    version: "0.0.0"
166
+  fluttertoast:
167
+    dependency: "direct dev"
168
+    description:
169
+      name: fluttertoast
170
+      url: "https://pub.dartlang.org"
171
+    source: hosted
172
+    version: "8.0.9"
161 173
   get:
162 174
     dependency: "direct main"
163 175
     description:
@@ -179,6 +191,13 @@ packages:
179 191
       url: "https://pub.dartlang.org"
180 192
     source: hosted
181 193
     version: "4.0.0"
194
+  js:
195
+    dependency: transitive
196
+    description:
197
+      name: js
198
+      url: "https://pub.dartlang.org"
199
+    source: hosted
200
+    version: "0.6.3"
182 201
   json_annotation:
183 202
     dependency: transitive
184 203
     description:
@@ -347,3 +366,4 @@ packages:
347 366
     version: "3.1.0"
348 367
 sdks:
349 368
   dart: ">=2.16.1 <3.0.0"
369
+  flutter: ">=1.10.0"

+ 2
- 0
pubspec.yaml 查看文件

@@ -51,6 +51,7 @@ dev_dependencies:
51 51
   flutter_lints: ^1.0.0
52 52
   json_serializable: ^6.1.5
53 53
   flutter_screenutil: ^5.3.1
54
+  fluttertoast: ^8.0.9
54 55
 # For information on the generic Dart part of this file, see the
55 56
 # following page: https://dart.dev/tools/pub/pubspec
56 57
 
@@ -64,6 +65,7 @@ flutter:
64 65
   # To add images to your application, add an images section, like this:
65 66
   assets:
66 67
     - images/icon_login.png
68
+    - images/phoneCode.png
67 69
 
68 70
   # An image asset can refer to one or more resolution-specific "variants", see
69 71
   # https://flutter.dev/assets-and-images/#resolution-aware.