18.2 送货地址栏位

18.2 送货地址栏位

image-20220729101241288

实现步骤:


第 1 步:UserService 加入送货地址简述

lib/common/services/user.dart

1
2
3
/// 送货地址
String get shipping =>
"${profile.shipping?.address1}, ${profile.shipping?.postcode}, ${profile.shipping?.state}, ${profile.shipping?.country}";

第 2 步:控制器

lib/pages/cart/buy_now/controller.dart

1
2
// 送货地址
String shippingAddress = "";
1
2
3
4
5
6
// 初始
_initData() {
shippingAddress = UserService.to.shipping;

update(["buy_now"]);
}
1
2
3
4
5
6
7
8
9
// goto 送货地址修改
Future<void> onShippingTap() async {
var result = await Get.toNamed(RouteNames.myMyAddress,
arguments: {"type": "Shipping"});
if (result != null && result == true) {
shippingAddress = UserService.to.shipping;
update(["buy_now"]);
}
}

第 3 步:视图

lib/pages/cart/buy_now/view.dart

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// 送货地址
Widget _buildShipping() {
return <Widget>[
// 文字
TextWidget.body1(controller.shippingAddress).expanded(),

// 图标
IconWidget.icon(
Icons.arrow_drop_down,
size: 32,
),
]
.toRow()
.paddingAll(AppSpace.button)
.decorated(
color: AppColors.surfaceVariant,
border: Border.all(
color: AppColors.outline,
width: 0.5,
),
borderRadius: BorderRadius.circular(AppRadius.button),
)
.onTap(controller.onShippingTap)
.paddingBottom(AppSpace.listRow);
}
1
2
3
4
5
6
7
8
9
// 主视图
Widget _buildView() {
return <Widget>[
...

// 送货地址
_buildTitle(LocaleKeys.placeOrderShippingAddress.tr),
_buildShipping(),

提交代码到 git