李志伟 пре 3 година
родитељ
комит
16d2a6e60d

images/icons/deletes.png → images/icons/delete.png Прегледај датотеку


+ 14
- 0
lib/models/entities/Address.dart Прегледај датотеку

@@ -0,0 +1,14 @@
1
+class Address {
2
+  String? address;
3
+  bool? isDefault;
4
+  Address();
5
+
6
+  Address.fromJson(Map<String, dynamic> json)
7
+      : address = json["address"],
8
+        isDefault = json["isDefault"];
9
+
10
+  Map<String, dynamic> toJson() => {
11
+        'address': address,
12
+        'isDefault': isDefault,
13
+      };
14
+}

+ 88
- 95
lib/pages/addressList/index.dart Прегледај датотеку

@@ -1,7 +1,9 @@
1
+import 'package:farmer_client/models/entities/Address.dart';
2
+import 'package:farmer_client/pages/addressList/widget/AddressCard.dart';
1 3
 import 'package:farmer_client/widgets/DefaultButton.dart';
2
-import 'package:flutter/cupertino.dart';
3 4
 import 'package:flutter/material.dart';
4 5
 import 'package:flutter_screenutil/flutter_screenutil.dart';
6
+import 'package:fluttertoast/fluttertoast.dart';
5 7
 
6 8
 class AddressList extends StatefulWidget {
7 9
   const AddressList({Key? key}) : super(key: key);
@@ -11,7 +13,52 @@ class AddressList extends StatefulWidget {
11 13
 }
12 14
 
13 15
 class _AddressList extends State<AddressList> {
14
-  bool isDetault = false;
16
+  bool isDefault = false;
17
+
18
+  List<Address> addressList = [
19
+    Address.fromJson({'address': '777', 'isDefault': false}),
20
+    Address.fromJson({'address': '999', 'isDefault': false}),
21
+    Address.fromJson({'address': '这是一个正经的地址', 'isDefault': false}),
22
+  ];
23
+  void onChange(index) {
24
+    setState(() {
25
+      addressList.forEach((element) {
26
+        if (element.isDefault == true) {
27
+          element.isDefault = false;
28
+        }
29
+      });
30
+      addressList[index].isDefault = true;
31
+    });
32
+  }
33
+  void onDelete(index){
34
+    showDialog(
35
+        context: context,
36
+        builder: (context) {
37
+          return AlertDialog(
38
+              title: Text("提示信息"),
39
+              content: Text("您确定要删除此地址吗?"),
40
+              actions: <Widget>[
41
+                TextButton(
42
+                  child: Text("取消"),
43
+                  onPressed: () {
44
+                    print("取消");
45
+                    Navigator.pop(context, 'Cancle');
46
+                  },
47
+                ),
48
+                TextButton(
49
+                    child: Text("确定"),
50
+                    onPressed: () {
51
+                      // setState(() {
52
+                      //   addressList.remove(addressList[e]);
53
+                      // });
54
+                      Navigator.pop(context, "Ok");
55
+                      Fluttertoast.showToast(
56
+                          msg: '删除成功!');
57
+                    })
58
+              ]);
59
+        });
60
+  }
61
+
15 62
   @override
16 63
   Widget build(BuildContext context) {
17 64
     return Scaffold(
@@ -28,101 +75,47 @@ class _AddressList extends State<AddressList> {
28 75
               fontWeight: FontWeight.bold),
29 76
         ),
30 77
       ),
31
-      body: Container(
32
-        padding: EdgeInsets.all(15.w),
33
-        child: Column(
34
-          //左对齐
35
-          crossAxisAlignment: CrossAxisAlignment.start,
36
-          children: [
37
-            Container(
38
-              width: 345.w,
39
-              padding: EdgeInsets.all(15.w),
40
-              margin: EdgeInsets.symmetric(vertical: 10.h, horizontal: 0),
41
-              decoration: BoxDecoration(
42
-                color: const Color(0xFFFFFFFF),
43
-                borderRadius: BorderRadius.all(Radius.circular(10.w)),
44
-                boxShadow: [
45
-                  BoxShadow(
46
-                      color: const Color(0x19000000),
47
-                      offset: Offset(0, 5.w),
48
-                      blurRadius: 12.w),
49
-                ],
50
-              ),
51
-              child: Column(
52
-                crossAxisAlignment: CrossAxisAlignment.start,
53
-                children: [
54
-                  Row(
55
-                    children: [
56
-                      Container(
57
-                        margin: EdgeInsets.fromLTRB(0, 0, 5.w, 0),
58
-                        padding: EdgeInsets.symmetric(
59
-                            vertical: 1.w, horizontal: 5.w),
60
-                        decoration: BoxDecoration(
61
-                          color: const Color(0xffff0000),
62
-                          borderRadius: BorderRadius.all(Radius.circular(5.w)),
63
-                        ),
64
-                        child: Text(
65
-                          '默认地址',
66
-                          style: TextStyle(
67
-                            fontSize: 15.sp,
68
-                            color: const Color(0xffffffff),
78
+      body: ListView(
79
+        children: [
80
+          Container(
81
+            padding: EdgeInsets.all(15.w),
82
+            child: Column(
83
+              //左对齐
84
+              crossAxisAlignment: CrossAxisAlignment.start,
85
+              children: [
86
+                Column(
87
+                    children: addressList
88
+                        .asMap()
89
+                        .keys
90
+                        .map(
91
+                          (e) => AddressCard(
92
+                            No: e + 1,
93
+                            item: addressList[e],
94
+                            onChange: () {
95
+                              onChange(e);
96
+                            },
97
+                            onEdit: () {},
98
+                            onDelete: () {
99
+                              onDelete(e);
100
+                            },
69 101
                           ),
70
-                        ),
71
-                      ),
72
-                      Text(
73
-                        '我的地址1',
74
-                        style: TextStyle(
75
-                            fontSize: 15.sp, fontWeight: FontWeight.w700),
76
-                      ),
77
-                    ],
78
-                  ),
79
-                  Container(
80
-                    decoration: BoxDecoration(
81
-                      border: Border(
82
-                        bottom: BorderSide(
83
-                            width: 0.5.h,
84
-                            color: const Color(0xcc000000),
85
-                            style: BorderStyle.solid),
86
-                      ),
87
-                    ),
88
-                    child: Row(
89
-                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
90
-                      children: [
91
-                        Container(
92
-                          padding: EdgeInsets.symmetric(vertical: 5.w,horizontal: 0),
93
-                          width:310.w,
94
-                          child: Text(
95
-                            '666666',
96
-                            style: TextStyle(
97
-                              fontSize: 15.sp,
98
-                              color: const Color(0xff666666),
99
-                            ),
100
-                          ),
101
-                        ),
102
-                        Image.asset('')
103
-                      ],
104
-                    ),
105
-                  ),
106
-                  const Text('我的地址'),
107
-                  const Text('6666'),
108
-                  const Text('设为默认地址:')
109
-                ],
110
-              ),
111
-            ),
112
-            if (!isDetault) const Text('66'),
113
-            DefaultButton(
114
-              color: const Color(0xffffffff),
115
-              backColor: const Color(0xFFFF703B),
116
-              width: 345.w,
117
-              height: 49.h,
118
-              text: '+新增收货地址',
119
-              onPressed: () {},
120
-              margin: const EdgeInsets.all(0),
121
-              fontSize: 20.sp,
122
-              radius: 24.5.w,
102
+                        )
103
+                        .toList()),
104
+                DefaultButton(
105
+                  color: const Color(0xffffffff),
106
+                  backColor: const Color(0xFFFF703B),
107
+                  width: 345.w,
108
+                  height: 49.h,
109
+                  text: '+新增收货地址',
110
+                  onPressed: () {},
111
+                  margin: const EdgeInsets.all(0),
112
+                  fontSize: 20.sp,
113
+                  radius: 24.5.w,
114
+                ),
115
+              ],
123 116
             ),
124
-          ],
125
-        ),
117
+          ),
118
+        ],
126 119
       ),
127 120
     );
128 121
   }

+ 154
- 0
lib/pages/addressList/widget/AddressCard.dart Прегледај датотеку

@@ -0,0 +1,154 @@
1
+import 'package:farmer_client/models/entities/Address.dart';
2
+import 'package:flutter/material.dart';
3
+import 'package:flutter_screenutil/flutter_screenutil.dart';
4
+import 'package:get/get_rx/src/rx_typedefs/rx_typedefs.dart';
5
+
6
+class AddressCard extends StatefulWidget {
7
+  final Address item;
8
+  final int No;
9
+  final GestureTapCallback onChange;
10
+  final GestureTapCallback onDelete;
11
+  final GestureTapCallback onEdit;
12
+  AddressCard(
13
+      {Key? key,
14
+      required this.item,
15
+      required this.No,
16
+      required this.onChange,
17
+      required this.onDelete,
18
+      required this.onEdit})
19
+      : super(key: key);
20
+
21
+  @override
22
+  _AddressCard createState() =>
23
+      _AddressCard(item, No, onChange, onDelete, onEdit);
24
+}
25
+
26
+class _AddressCard extends State<AddressCard> {
27
+  bool isDetault = false;
28
+  final Address item;
29
+  final int No;
30
+  final GestureTapCallback onChange;
31
+  final GestureTapCallback onDelete;
32
+  final GestureTapCallback onEdit;
33
+  _AddressCard(this.item, this.No, this.onChange, this.onDelete, this.onEdit);
34
+  @override
35
+  Widget build(BuildContext context) {
36
+    return Container(
37
+      width: 345.w,
38
+      padding: EdgeInsets.all(15.w),
39
+      margin: EdgeInsets.fromLTRB(0, 0, 0, 15.w),
40
+      decoration: BoxDecoration(
41
+        color: const Color(0xFFFFFFFF),
42
+        borderRadius: BorderRadius.all(Radius.circular(10.w)),
43
+        boxShadow: [
44
+          BoxShadow(
45
+              color: const Color(0x19000000),
46
+              offset: Offset(0, 5.w),
47
+              blurRadius: 12.w),
48
+        ],
49
+      ),
50
+      child: Column(
51
+        crossAxisAlignment: CrossAxisAlignment.start,
52
+        children: [
53
+          Row(
54
+            children: [
55
+              if (item.isDefault == true)
56
+                Container(
57
+                  margin: EdgeInsets.fromLTRB(0, 0, 5.w, 0),
58
+                  padding: EdgeInsets.symmetric(vertical: 1.w, horizontal: 5.w),
59
+                  decoration: BoxDecoration(
60
+                    color: const Color(0xffff0000),
61
+                    borderRadius: BorderRadius.all(Radius.circular(5.w)),
62
+                  ),
63
+                  child: Text(
64
+                    '默认地址',
65
+                    style: TextStyle(
66
+                      fontSize: 15.sp,
67
+                      fontWeight: FontWeight.bold,
68
+                      color: const Color(0xffffffff),
69
+                    ),
70
+                  ),
71
+                ),
72
+              Text(
73
+                '我的地址' + No.toString(),
74
+                style: TextStyle(fontSize: 15.sp, fontWeight: FontWeight.w700),
75
+              ),
76
+            ],
77
+          ),
78
+          GestureDetector(
79
+            onTap: onEdit,
80
+            child: Container(
81
+              padding: EdgeInsets.symmetric(vertical: 5.h, horizontal: 0),
82
+              decoration: BoxDecoration(
83
+                border: Border(
84
+                  bottom: BorderSide(
85
+                      width: 0.5.h,
86
+                      color: const Color(0xcc000000),
87
+                      style: BorderStyle.solid),
88
+                ),
89
+              ),
90
+              child: Row(
91
+                mainAxisAlignment: MainAxisAlignment.spaceBetween,
92
+                children: [
93
+                  Container(
94
+                    padding: EdgeInsets.symmetric(vertical: 5.w, horizontal: 0),
95
+                    width: 282.w,
96
+                    child: Text(
97
+                      item.address.toString(),
98
+                      //最多显示两行
99
+                      maxLines: 2,
100
+                      //多余文本用点点点表示
101
+                      overflow: TextOverflow.ellipsis,
102
+                      style: TextStyle(
103
+                        fontSize: 15.sp,
104
+                        color: const Color(0xff666666),
105
+                      ),
106
+                    ),
107
+                  ),
108
+                  Image.asset(
109
+                    'images/icons/edit.png',
110
+                    width: 33.w,
111
+                    height: 33.w,
112
+                  ),
113
+                ],
114
+              ),
115
+            ),
116
+          ),
117
+          Row(
118
+            mainAxisAlignment: MainAxisAlignment.spaceBetween,
119
+            children: [
120
+              GestureDetector(
121
+                onTap: onChange,
122
+                child: Row(
123
+                  children: [
124
+                    const Text('设为默认地址'),
125
+                    Radio<bool>(
126
+                        value: true,
127
+                        activeColor: const Color(0xFFFF703B),
128
+                        groupValue: item.isDefault,
129
+                        onChanged: (value){
130
+                          onChange();
131
+                        }),
132
+                  ],
133
+                ),
134
+              ),
135
+              GestureDetector(
136
+                onTap: onDelete,
137
+                child: Row(
138
+                  children: [
139
+                    const Text('删除'),
140
+                    Image.asset(
141
+                      'images/icons/delete.png',
142
+                      width: 25.w,
143
+                      height: 25.w,
144
+                    ),
145
+                  ],
146
+                ),
147
+              ),
148
+            ],
149
+          ),
150
+        ],
151
+      ),
152
+    );
153
+  }
154
+}

+ 2
- 0
pubspec.yaml Прегледај датотеку

@@ -89,6 +89,8 @@ flutter:
89 89
     - images/logo.png
90 90
     - images/splash.png
91 91
     - images/icons/decorate.png
92
+    - images/icons/edit.png
93
+    - images/icons/delete.png
92 94
     - images/ordersListImga.png
93 95
 
94 96
   # An image asset can refer to one or more resolution-specific "variants", see