18.2 送货地址栏位
实现步骤:
第 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
| 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