当前位置: 首页 > backend >正文

Flutter:步骤条组件

在这里插入图片描述

组件封装

import 'package:flutter/material.dart';class SubscribeStepWidget extends StatelessWidget {final List<Map<String, dynamic>> steps;final int current;final Axis axis;final Color? themeColor;const SubscribeStepWidget({Key? key,required this.steps,required this.current,this.axis = Axis.vertical, // 默认竖向this.themeColor,}) : super(key: key);@overrideWidget build(BuildContext context) {if (axis == Axis.horizontal) {// 横向略return Row(mainAxisAlignment: MainAxisAlignment.spaceBetween,children: _buildHorizontalSteps(),);}// 竖向return Column(crossAxisAlignment: CrossAxisAlignment.start,children: _buildVerticalSteps(context),);}List<Widget> _buildVerticalSteps(BuildContext context) {final Color mainColor = themeColor ?? Colors.blue;List<Widget> widgets = [];for (int i = 0; i < steps.length; i++) {final step = steps[i];final isActive = i + 1 == current;final isFinished = i + 1 < current;widgets.add(IntrinsicHeight(child: Row(crossAxisAlignment: CrossAxisAlignment.start,children: [// 步骤圆圈和竖线Column(children: [Container(width: 20,height: 20,alignment: Alignment.center,decoration: BoxDecoration(color: isActive? mainColor: isFinished? mainColor.withOpacity(0.3): Colors.white,border: Border.all(color: isActive? mainColor: isFinished? mainColor.withOpacity(0.3): Colors.grey,width: 2,),shape: BoxShape.circle,),child: Center(child: isFinished? Icon(Icons.check, size: 16, color: Colors.white): Text('${step['index']}',style: TextStyle(color: isActive? Colors.white: isFinished? Colors.white: Colors.grey,fontWeight: FontWeight.bold,),),),),// 竖线自适应if (i != steps.length - 1)Expanded(child: Container(width: 2,color: isFinished || isActive? mainColor.withOpacity(0.3): Colors.grey[300],),),],),const SizedBox(width: 12),// 标题和内容Expanded(child: Container(padding: const EdgeInsets.only(bottom: 20),child: Column(crossAxisAlignment: CrossAxisAlignment.start,children: [Text(step['title'] ?? '',style: TextStyle(fontSize: 16,fontWeight: isActive ? FontWeight.bold : FontWeight.normal,color: isActive? mainColor: Colors.black87,),),if (step['desc'] != null)Padding(padding: const EdgeInsets.only(top: 4, bottom: 8),child: Text(step['desc'],style: TextStyle(fontSize: 14,color: Colors.grey[600],),maxLines: 2,overflow: TextOverflow.ellipsis,),),if (step['time'] != null)Text(step['time'],style: TextStyle(fontSize: 12,color: Colors.grey[400],),),],),),),],),),);}return widgets;}// 横向略(如需可补充)List<Widget> _buildHorizontalSteps() => [];
}

调用

  // 当前周期int current = 2;List<Map<String, dynamic>> timeList = [{'index': 1,'title': '项目预热','desc': '阶段1简介','time': '2025.03.20 22:25:26',},{'index': 2,'title': '开始申购','desc': '阶段2简介','time': '2025.03.20 22:25:26',},{'index': 3,'title': '结束申购','desc': '阶段3简介','time': '2025.03.20 22:25:26',},{'index': 4,'title': '公布结果','desc': '阶段4简介','time': '2025.03.20 22:25:26',},];SubscribeStepWidget(steps: controller.timeList,current: controller.current,axis: Axis.vertical, // 或 Axis.verticalthemeColor: AppTheme.colorGreen,
),
http://www.xdnf.cn/news/13991.html

相关文章:

  • Wi-Fi 6 在 2.4GHz 频段的速率与优化分析
  • Unit 3 训练一个Q-Learning智能体 Frozen-Lake-v1
  • 基于springboot视频及游戏管理系统+源码+文档+应用视频
  • RTP MOS计算:语音质量的数字评估
  • STM32HAL库发送字符串,将uint8_t数据转为字符串发送,sprintf函数的使用方法
  • 声学成像仪在电力行业的应用品牌推荐
  • Java从入门到精通 - 面向对象高级(一)
  • vllm eagle支持分析
  • 燃气从业人员资格证书:开启职业大门的 “金钥匙”
  • Ntfs!NtfsInitializeRestartTable函数分析
  • 资金分析怎么做?如何预防短期现金流风险?
  • 刀客doc:WPP走下神坛
  • 中国AI Top30 访问量排行榜 - 2025年05月
  • 外部记忆的组织艺术:集合、树、栈与队列的深度解析
  • 燃气从业人员资格证书:职业发展的 “助推器”
  • 灌区信息化智能一体化闸门系统解决方案
  • 学习STC51单片机36(芯片为STC89C52RCRC)智能小车3(PWM差速小车)
  • 【软件安装那些事 4】CAD字体 SHX格式字库 免费 下载 及 使用方法
  • python中的分支结构:单分支、多分支,switch语句
  • JeecgBoot Pro-Online表单开发
  • 【经验篇】自签名TLS证书生成
  • 博客园突发大规模DDoS攻击 - 深度解析云安全防御新范式
  • P10987 [蓝桥杯 2023 国 Python A] 火车运输
  • 第一章 数字电路概述
  • 记一次错误 深拷贝 key值全部小写
  • 三次握手建立连接,四次挥手释放连接——TCP协议的核心机制
  • 上海市计算机学会竞赛平台2022年6月月赛丙组模糊匹配
  • 蚂蚁国际计划在香港和新加坡推出稳定币
  • 关于UEFI:UEFI/BIOS 固件分析
  • 【51单片机】6. 定时器、按键切换流水灯时钟Demo