李志伟 3 years ago
parent
commit
5e7cf8db6d
3 changed files with 120 additions and 3 deletions
  1. 109
    0
      lib/pages/addAddress/index.dart
  2. 8
    2
      lib/pages/addressList/index.dart
  3. 3
    1
      lib/routes/pages.dart

+ 109
- 0
lib/pages/addAddress/index.dart View File

@@ -1 +1,110 @@
1
+import 'package:farmer_client/models/entities/Address.dart';
2
+import 'package:farmer_client/widgets/DefaultButton.dart';
1 3
 import 'package:flutter/material.dart';
4
+import 'package:flutter_screenutil/flutter_screenutil.dart';
5
+import 'package:fluttertoast/fluttertoast.dart';
6
+import 'package:get/get.dart';
7
+
8
+class AddAddress extends StatefulWidget {
9
+  const AddAddress({Key? key}) : super(key: key);
10
+
11
+  @override
12
+  _AddAddress createState() => _AddAddress();
13
+}
14
+
15
+class _AddAddress extends State<AddAddress> {
16
+  late Address address=Address();
17
+  late String text = '';
18
+
19
+  @override
20
+  void initState() {
21
+    super.initState();
22
+    if (Get.arguments != null) {
23
+      address = Get.arguments['item'];
24
+      text = address.address.toString();
25
+    }
26
+  }
27
+
28
+  @override
29
+  Widget build(BuildContext context) {
30
+    return Scaffold(
31
+      appBar: AppBar(
32
+        elevation: 0,
33
+        centerTitle: true,
34
+        backgroundColor: Colors.white,
35
+        title: Text(
36
+          '添加地址',
37
+          style: TextStyle(
38
+              color: Colors.black,
39
+              fontSize: 17.sp,
40
+              letterSpacing: 2,
41
+              fontWeight: FontWeight.bold),
42
+        ),
43
+      ),
44
+      body: Container(
45
+        padding: EdgeInsets.all(15.w),
46
+        child: Column(
47
+          crossAxisAlignment: CrossAxisAlignment.start,
48
+          children: [
49
+            Text(
50
+              '详细地址:',
51
+              style: TextStyle(
52
+                  fontWeight: FontWeight.bold,
53
+                  fontSize: 17.sp,
54
+                  color: const Color(0xFF333333)),
55
+            ),
56
+            Container(
57
+              margin: EdgeInsets.fromLTRB(0, 0, 0, 50.h),
58
+              padding: EdgeInsets.symmetric(vertical: 5.w, horizontal: 18.5.w),
59
+              decoration: BoxDecoration(
60
+                  color: const Color(0xFFfefefe),
61
+                  borderRadius: BorderRadius.all(Radius.circular(10.w)),
62
+                  border: Border.all(
63
+                      color: const Color(0xcc000000),
64
+                      width: 1.h,
65
+                      style: BorderStyle.solid)),
66
+              child: TextFormField(
67
+                initialValue: text,
68
+                minLines: 6,
69
+                maxLines: 6,
70
+                style: TextStyle(fontSize: 17.sp, height: 1.5),
71
+                decoration: const InputDecoration(
72
+                  isCollapsed: true,
73
+                  hintText: '请输入地址信息',
74
+                  border: InputBorder.none,
75
+                  counterText: '', //去掉计数
76
+                  floatingLabelBehavior: FloatingLabelBehavior.never,
77
+                ),
78
+                onChanged: (e) {
79
+                  setState(() {
80
+                    address.address = e;
81
+                  });
82
+                },
83
+              ),
84
+            ),
85
+            DefaultButton(
86
+              color: const Color(0xffffffff),
87
+              backColor: const Color(0xFFFF703B),
88
+              width: 345.w,
89
+              height: 49.h,
90
+              text: '保存',
91
+              onPressed: () {
92
+                if(address.address==null){
93
+                  Fluttertoast.showToast(
94
+                      msg: '请输入地址!');
95
+                } else{
96
+                  Fluttertoast.showToast(
97
+                      msg: '保存成功!');
98
+                  Get.back();
99
+                }
100
+              },
101
+              margin: const EdgeInsets.all(0),
102
+              fontSize: 20.sp,
103
+              radius: 24.5.w,
104
+            ),
105
+          ],
106
+        ),
107
+      ),
108
+    );
109
+  }
110
+}

+ 8
- 2
lib/pages/addressList/index.dart View File

@@ -4,6 +4,8 @@ import 'package:farmer_client/widgets/DefaultButton.dart';
4 4
 import 'package:flutter/material.dart';
5 5
 import 'package:flutter_screenutil/flutter_screenutil.dart';
6 6
 import 'package:fluttertoast/fluttertoast.dart';
7
+import 'package:get/get.dart';
8
+
7 9
 
8 10
 class AddressList extends StatefulWidget {
9 11
   const AddressList({Key? key}) : super(key: key);
@@ -93,7 +95,9 @@ class _AddressList extends State<AddressList> {
93 95
                             onChange: () {
94 96
                               onChange(e);
95 97
                             },
96
-                            onEdit: () {},
98
+                            onEdit: () {
99
+                              Get.toNamed('/addAddress',arguments: {'item':addressList[e]});
100
+                            },
97 101
                             onDelete: () {
98 102
                               onDelete(e);
99 103
                             },
@@ -106,7 +110,9 @@ class _AddressList extends State<AddressList> {
106 110
                   width: 345.w,
107 111
                   height: 49.h,
108 112
                   text: '+新增收货地址',
109
-                  onPressed: () {},
113
+                  onPressed: () {
114
+                    Get.toNamed('/addAddress');
115
+                  },
110 116
                   margin: const EdgeInsets.all(0),
111 117
                   fontSize: 20.sp,
112 118
                   radius: 24.5.w,

+ 3
- 1
lib/routes/pages.dart View File

@@ -1,8 +1,9 @@
1 1
 
2 2
 import 'package:farmer_client/pages/ArticleInfo/ArticleInfo.dart';
3
+import 'package:farmer_client/pages/addAddress/index.dart';
3 4
 import 'package:farmer_client/pages/addressList/index.dart';
4 5
 import 'package:get/get.dart';
5
-import '../pages/index.dart';//Home
6
+import '../pages/index.dart';
6 7
 
7 8
 
8 9
 List<GetPage> pages = [
@@ -11,4 +12,5 @@ GetPage(name: '/ArticleInfo', page: () =>  ArticleInfo()),//资讯详情
11 12
 GetPage(name: '/splash', page: () => SplashScreen()),
12 13
 GetPage(name: '/login', page: () =>  MyRouteLogin()),
13 14
 GetPage(name: '/addressList', page: () =>  AddressList()),
15
+GetPage(name: '/addAddress', page: () =>  AddAddress()),
14 16
 ];