19.3 状态横向展示
实现步骤:
lib/common/components/steps.dart
定义状态枚举,三态
1 2 3 4 5 6
| enum StepStatus { none, running, success, }
|
横向滚动组件
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
| class StepHorizontalItemWidget extends StatelessWidget { final String statusName;
final StepStatus status;
const StepHorizontalItemWidget({ Key? key, required this.statusName, this.status = StepStatus.none, }) : super(key: key);
@override Widget build(BuildContext context) { return LayoutBuilder( builder: (BuildContext context, BoxConstraints constraints) { return <Widget>[ <Widget>[ Container( color: AppColors.surfaceVariant.withOpacity(0.5), height: 3, ), if (status == StepStatus.success) Container( color: AppColors.primary, height: 3, ), if (status == StepStatus.running) Container( color: AppColors.primary, height: 3, width: constraints.minWidth / 2, ).alignLeft(), Container( height: 7, width: 7, decoration: BoxDecoration( color: status == StepStatus.none ? AppColors.surfaceVariant.withOpacity(0.5) : AppColors.primary, borderRadius: const BorderRadius.all( Radius.circular(7 / 2), ), ), ), ] .toStack( alignment: Alignment.center, ) .paddingBottom(AppSpace.iconTextSmail),
TextWidget.body3( statusName, ), ].toColumn(); }, ).expanded(); } }
|
第 2 步:视图
lib/pages/my/order_details/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 26 27 28 29 30 31 32 33
| Widget _buildHorizontalStatus() { return <Widget>[ const StepHorizontalItemWidget( statusName: "Pending", status: StepStatus.success, ), const StepHorizontalItemWidget( statusName: "Confirmed", status: StepStatus.success, ), const StepHorizontalItemWidget( statusName: "Processing", status: StepStatus.running, ), const StepHorizontalItemWidget( statusName: "Picked", status: StepStatus.none, ), const StepHorizontalItemWidget( statusName: "Shipped", status: StepStatus.none, ), const StepHorizontalItemWidget( statusName: "Delivered", status: StepStatus.none, ), ].toRow().padding( bottom: AppSpace.listRow, left: AppSpace.page, right: AppSpace.page, ); }
|
这里的状态更适合 完整的快递配送流程,这里只做 UI 展示,大家按需要调整
提交代码到 git