|
@@ -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
|
}
|