19.6 购买品名列表栏
实现步骤:
第 1 步:组件 BuildProductList
lib/pages/my/order_details/widgets/products_list.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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
| import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_woo_commerce_getx_learn/common/index.dart'; import 'package:get/get.dart';
class BuildProductList extends StatelessWidget { const BuildProductList({ Key? key, required this.lineItems, this.currencySymbol, }) : super(key: key);
final List<LineItem> lineItems;
final String? currencySymbol;
TableRow _tableHeader() { return TableRow( children: [ const SizedBox(width: 50), TextWidget.body1(LocaleKeys.orderDetailsProduct.tr), TextWidget.body1(LocaleKeys.orderDetailsRateQty.tr), TextWidget.body1(LocaleKeys.orderDetailsAmount.tr), ], ); }
Widget _buildView() { List<TableRow> ws = [];
ws.add(_tableHeader());
for (int i = 0; i < lineItems.length; i++) { LineItem item = lineItems[i]; TableRow tr = TableRow(children: [ TextWidget.body2("${i + 1}").alignCenter(),
<Widget>[ ImageWidget.url( Convert.aliImageResize(item.product?.images?[0].src ?? "", width: 140), width: 70.w, height: 70.w, radius: AppRadius.image, ), TextWidget.body2(item.product?.name ?? ""), ].toColumn( crossAxisAlignment: CrossAxisAlignment.start, ),
TextWidget.body2( "${item.price} x ${item.quantity}", ),
TextWidget.body2("$currencySymbol ${item.total}"), ]); ws.add(tr); }
return Table( columnWidths: const { 0: FixedColumnWidth(50.0), 2: FixedColumnWidth(100.0), 3: FixedColumnWidth(80.0), }, defaultVerticalAlignment: TableCellVerticalAlignment.middle, children: ws, ); }
@override Widget build(BuildContext context) { return _buildView(); } }
|
第 2 步:视图
lib/pages/my/order_details/view.dart
1 2 3 4 5 6 7
| Widget _buildProductsList() { return BuildProductList( lineItems: controller.order.lineItems ?? [], currencySymbol: controller.order.currencySymbol, ).paddingAll(AppSpace.card).card().paddingBottom(AppSpace.listRow); }
|
提交代码到 git