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

Flutter---ListTile列表项组件

概述:ListTile​​ 是 Flutter 中一个非常常用的 Material Design 列表项组件,专门用于构建列表中的每一项。

基本属性:

ListTile(leading: Icon(Icons.person),        // 前导图标title: Text('用户名'),               // 主标题subtitle: Text('用户昵称'),          // 副标题trailing: Icon(Icons.arrow_forward), // 后置图标onTap: () {},                       // 点击事件
)

完整属性列表

ListTile(// 1. 内容区域leading: Widget,                    // 左侧部件title: Widget,                      // 主标题subtitle: Widget,                   // 副标题trailing: Widget,                   // 右侧部件// 2. 交互相关onTap: () => void,                  // 点击回调onLongPress: () => void,            // 长按回调onFocusChange: (bool) => void,      // 焦点变化onTap: () => void,                  // 点击回调mouseCursor: MouseCursor,           // 鼠标样式enabled: bool,                      // 是否启用// 3. 样式相关style: ListTileStyle,               // 样式类型selected: bool,                     // 选中状态selectedColor: Color,               // 选中颜色iconColor: Color,                   // 图标颜色textColor: Color,                   // 文字颜色contentPadding: EdgeInsets,         // 内边距dense: bool,                        // 紧凑模式visualDensity: VisualDensity,       // 视觉密度shape: ShapeBorder,                 // 形状tileColor: Color,                   // 背景色selectedTileColor: Color,           // 选中背景色focusColor: Color,                  // 焦点颜色hoverColor: Color,                  // 悬停颜色splashColor: Color,                 // 水波纹颜色horizontalTitleGap: double,         // 标题水平间距minVerticalPadding: double,         // 最小垂直内边距minLeadingWidth: double,            // 最小前导宽度// 4. 辅助功能autofocus: bool,                    // 自动聚焦focusNode: FocusNode,               // 焦点节点
)

使用例子

//========================修改性别的弹窗========================================//void changeGenderDialog() {showDialog(context: context,builder: (context) {return Dialog(backgroundColor: Colors.white, //背景颜色shape: RoundedRectangleBorder( //形状配置borderRadius: BorderRadius.circular(26),),child: Container(width: 250, // 自定义宽度padding: EdgeInsets.all(16), // 内边距child: Column(mainAxisSize: MainAxisSize.min,children: [// 男性选项ListTile(dense: true, //紧凑模式title: Text("男", style: TextStyle(fontSize: 16, color: Color(0xFF3D3D3D))),trailing: _selectedGender == "男" //只有选中“男”,才显示男性行尾部图标(三元运算符)? Image.asset("assets/images/cherry.png", width: 24, height: 24): null,//点击事件onTap: () {Navigator.pop(context);//关闭对话框setState(() {_selectedGender = "男"; //更新性别变量值});widget.onGenderChanged("男");// 调用回调函数,传值回主页},),// 女性选项ListTile(dense: true,//紧凑模式title: Text("女", style: TextStyle(fontSize: 16, color: Color(0xFF3D3D3D))),trailing: _selectedGender == "女" //只有选中“女”,才显示女性行尾部图标? Image.asset("assets/images/cherry.png", width: 24, height: 24): null,onTap: () {Navigator.pop(context);setState(() {_selectedGender = "女";  //更新性别变量值});widget.onGenderChanged("女");// 调用回调函数,传值回主页},),],),),);},);}

http://www.dtcms.com/a/548528.html

相关文章:

  • Spring Boot入门篇:快速搭建你的第一个Spring Boot应用
  • 《算法通关指南数据结构和算法篇(1)--- 顺序表相关算法题》
  • ReentrantLock 加锁与解锁流程详解(源码分析,小白易懂)
  • 鸿蒙Flutter三方库适配指南:06.插件适配原理
  • Linux 防火墙实战:用 firewalld 配置 External/Internal 区域,实现 NAT 内网共享上网
  • Java 学习29:方法
  • Kafka 全方位详细介绍:从架构原理到实践优化
  • Obsidian 入门教程(二)
  • [测试工具] 如何把离线的项目加入成为git项目的新分支
  • 让数据导入导出更智能:通用框架+验证+翻译的一站式解决方案
  • 今天我们学习Linux架构keepalived实现LVS代理双击热备
  • [Linux]内核队列实现详解
  • 【Spring Cloud】Spring Cloud Config
  • MySQL | 数据查询DQL语言:分组统计
  • 阿里云灵码IDE技术测评:从v0.1.0到v0.1.5的进化之路
  • 江门网站推广技巧asp网站服务建设
  • C++: inline 与 ODR,冲突的诞生
  • 营销型 展示类网站企业网站建设空间
  • 从单体到微服务:Java的分布式演进与工程实战
  • 【论文笔记】扩散模型——如何通俗理解传统概率模型的核心矛盾
  • android15 实现截屏功能
  • 工业4.0数据中枢:重构产品全生命周期的智能设计范式
  • 深度解析《AI+Java编程入门》:一本为零基础重构的Java学习路径
  • 架构论文《论数字孪生系统架构设计与应用》
  • 郑州网站建设汉狮如何让百度收录自己的网站信息
  • 英一2017年真题学习笔记
  • PaddleOCR-VL对标DeepSeek-OCR?
  • DeepSeek-OCR 论文精读与实践:用“光学上下文压缩”把长文本变成图片,再由 VLM 高效还原
  • 创新网站内容建设企业建网站的案例
  • 沈阳建站模板系统包括如何自己创建一个网页