flutter 学习笔记之写一个通用的设置页面

这篇博客分享了如何在Flutter中编写一个通用的设置页面组件。通过源码链接和核心代码展示,作者封装了一个小控件,该控件支持自定义左侧图标和文字,右侧文字及可选箭头,并默认显示下划线。此代码片段适用于未来开发中的设置页面。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

源码https://github.com/AnleSu/select_text_item

效果图:

 

核心code:

Widget build(BuildContext context) {
    return GestureDetector(
      onTap: this.onTap,
      child: Container(
        height: this.height ?? 50.0,
        margin: EdgeInsets.only(left: 16, right: 16),
        width: double.infinity,
        decoration: BoxDecoration(
            border: Border(
                //下面的分割线 width 这个参数应该是控制分割线高度的
                bottom: Divider.createBorderSide(context,
                    color: Color(0xFFEEEEEE), width: 1))),
        child: Row(
          children: <Widget>[
            this.imageName == null
                ? Container()
                : Image.asset(
                    '${this.imageName}',
                    width: 22,
                    height: 22,
                  ),
            Text(this.title,
                style: this.titleStyle ??
                    new TextStyle(
                      color: Color(0xFF333333),
                      fontSize: 14.0,
                    )),
            Expanded(
              child: Container(
                padding: EdgeInsets.only(left: 16, right: 16),
                child: Text(this.content,
                    textAlign: this.textAlign,
                    overflow: TextOverflow.ellipsis,
                    style: this.contentStyle ??
                        new TextStyle(
                          fontSize: 14.0,
                          color: Color(0xFFCCCCCC),
                        )),
              ),
            ),
            //这里为了方便用了系统icon 可以设置一张arrow 的图片
            // Image.asset(
            //   '',
            //   width: 16,
            //   height: 16,
            // )
            this.isShowArrow
                ? Icon(
                    Icons.arrow_forward_ios,
                    size: 16,
                  )
                : Container(),
          ],
        ),
      ),
    );
  }

封装了一个简单的小控件,支持设置左侧的图片和文字,右侧的文字和箭头是否显示,默认显示下面的横线

test code:

SelectTextItem(
            title: '密保手机号',
            content: '131****3987',
            textAlign: TextAlign.end,
            contentStyle: new TextStyle(
              fontSize: 15,
              color: Color(0xFF333333),
            ),
          ),

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值