Flutter ListTile - Flutter每周一组件

flutter_week

该文章属于【Flutter每周一组件】系列,其它组件可以查看该系列下的文章,该系列会不间断更新;所有组件的demo已经上传值Github: https://github.com/xj124456/flutter_widget_demo 欢迎Star

博客:思否, 掘金, 知乎, 简书, 慕课, CSDN, 博客园, DX前端
公众号:DX前端框架知识库
联系我:公众号菜单点击联系我

使用场景

  1. 组件解释:固定高度的单个行,通常包含一些文本以及前导或尾随图标。
  2. 当需要给一个列表list的时候,你可以用ListTile来实现,它可以将元素一行一行的展示出来,并且你可以给每个元素绑定事件,一个ListTile就是一行

预览

组件参数说明

const ListTile({
    Key key,
    this.leading, //左侧的组件
    this.title, //中间的主标题
    this.subtitle, //中间的副标题
    this.trailing, //右侧组件,通常是一个值或者一个图标
    this.isThreeLine = false, //是否显示三行
    this.dense, //是否以垂直密集的方式显示,这样文字会更小
    this.visualDensity,
    this.shape, //定义外观形状
    this.contentPadding, //内容与边框之间的边距,默认16
    this.enabled = true, //是否可以互动事件
    this.onTap, //点击事件
    this.onLongPress, //长按事件
    this.mouseCursor, //鼠标悬停在ListTile上时的处理效果,给web用的
    this.selected = false, //如果是true,文本和图标将会以相同的颜色呈现
    this.focusColor, 
    this.hoverColor, //指针悬停在ListTile上的颜色
    this.focusNode, //聚焦事件
    this.autofocus = false, //是否默认聚焦
    this.tileColor, //listTile的背景颜色,selected=false时生效
    this.selectedTileColor, //listTile的背景颜色,selected=true时生效
  })

案例代码

Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Text('Flutter ListTile'),
            Text(
              'Flutter每周一组件(by DX前端)',
              style: TextStyle(
                fontSize: 12.0,
              ),
            )
          ],
        ),
      ),
      body: Center(
          child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          ListTile(
            leading: Icon(Icons.graphic_eq),
            title: Text('这是主标题'),
            trailing: Icon(Icons.chevron_right),
          ),
          Divider(),
          ListTile(
            leading: Icon(Icons.waves),
            title: Text('这是主标题'),
            subtitle: Text('这是副标题'),
            trailing: Icon(Icons.chevron_right),
          ),
          Divider(),
          ListTile(
            leading: Icon(Icons.ballot),
            title: Text('这是主标题'),
            // isThreeLine: true, //文字超出后会默认换行
            subtitle: Text('这是副标题两行,这是副标题两行,这是副标题两行,这是副标题两行,这是副标题两行'),
            trailing: Icon(Icons.chevron_right),
          ),
          Divider(),
        ],
      )),
    );
  }

觉得有用 ?喜欢就收藏,顺便点个赞吧,你的支持是我最大的鼓励!微信搜公众号 [DX前端框架知识库],发现更多Vue, React, Flutter, Uniapp, Nodejs, Html/Css等前端知识和实战.

DX前端,分享前端框架知识库,文章详见:DX前端

关注DX前端

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Flutter ListTile是一个常用的UI组件,用于在列表中展示相关信息。它提供了一个整洁的外观和常见的交互模式,使得在Flutter应用中显示列表项变得简单。 ListTile通常用于在FlutterListView或GridView中展示每个列表项。它可以显示标题、副标题、前置图标、后置图标等内容。 在使用ListTile时,你可以设置以下属性: 1. title:列表项的主要内容,通常是一个Text或RichText组件。 2. subtitle:列表项的副标题,通常是一个Text或RichText组件。 3. leading:列表项的前置图标,通常是一个Icon或Image组件。 4. trailing:列表项的后置图标,通常是一个Icon或Image组件。 5. onTap:点击列表项时触发的回调函数。 除了以上属性,ListTile还有其他一些属性可以用来自定义样式,例如字体大小、颜色、边距等。 以下是一个使用ListTile的示例代码: ```dart ListView( children: <Widget>[ ListTile( leading: Icon(Icons.person), title: Text('John Doe'), subtitle: Text('Software Engineer'), trailing: Icon(Icons.arrow_forward), onTap: () { // 处理点击事件 }, ), ListTile( leading: Icon(Icons.person), title: Text('Jane Smith'), subtitle: Text('UI Designer'), trailing: Icon(Icons.arrow_forward), onTap: () { // 处理点击事件 }, ), // 其他列表项... ], ) ``` 这段代码创建了一个包含两个ListTileListView,每个ListTile代表一个人员信息,包括姓名、职位等内容。你可以根据自己的需求进行修改和扩展。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值