flutter 自定义九宫格,计算器布局,验证码认证

一言不合,直接丢代码

1、先写几个接收验证码的文本框

return Scaffold(
      backgroundColor: ColorsUtil.hexStringColor("#B1B1B1"),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Container(
                  margin: EdgeInsets.only(right: 12, left: 12),
                  width: 40,
                  decoration: BoxDecoration(
                      border: Border(
                          bottom: BorderSide(
                              width: 2,
                              color: ColorsUtil.hexStringColor("#F6F7FA")))),
                  child: Text(
                    "*",
                    textAlign: TextAlign.center,
                    style: TextStyle(
                      color: ColorsUtil.hexStringColor("#FFFFFF"),
                      fontSize: 24,
                    ),
                  ),
                ),
                Container(
                  margin: EdgeInsets.only(right: 12, left: 12),
                  width: 40,
                  decoration: BoxDecoration(
                      border: Border(
                          bottom: BorderSide(
                              width: 2,
                              color: ColorsUtil.hexStringColor("#F6F7FA")))),
                  child: Text(
                    "*",
                    textAlign: TextAlign.center,
                    style: TextStyle(
                      color: ColorsUtil.hexStringColor("#FFFFFF"),
                      fontSize: 24,
                    ),
                  ),
                ),
                Container(
                  margin: EdgeInsets.only(right: 12, left: 12),
                  width: 40,
                  decoration: BoxDecoration(
                      border: Border(
                          bottom: BorderSide(
                              width: 2,
                              color: ColorsUtil.hexStringColor("#F6F7FA")))),
                  child: Text(
                    "*",
                    textAlign: TextAlign.center,
                    style: TextStyle(
                      color: ColorsUtil.hexStringColor("#FFFFFF"),
                      fontSize: 24,
                    ),
                  ),
                ),
                Container(
                  margin: EdgeInsets.only(right: 12, left: 12),
                  width: 40,
                  decoration: BoxDecoration(
                      border: Border(
                          bottom: BorderSide(
                              width: 2,
                              color: ColorsUtil.hexStringColor("#F6F7FA")))),
                  child: Text(
                    "*",
                    textAlign: TextAlign.center,
                    style: TextStyle(
                      color: ColorsUtil.hexStringColor("#FFFFFF"),
                      fontSize: 24,
                    ),
                  ),
                ),
              ],
            ),
            SizedBox(
              height: 36,
            ),
            buildNumber(),
          ],
        ),
      ),
    );

2、代码循环生成对应按钮模块

  buildNumber() {
    List<Widget> tiles = [];
    Widget content;

    for (int i = 1; i <= 12; i++) {
      tiles.add(
        InkWell(child: getContainer(i),onTap: (){
          print(i.toString());
        },),
      );
    }

    content = Container(
      width: 300,
      alignment: Alignment.center,
      child: Wrap(
        children: tiles,
      ),
    );

    return content;
  }

3、修改边框,对应特殊符号等按钮

Widget getContainer(int index) {
    if (index == 10) {
      return Container(
        width: 89,
        height: 40,
      );
    } else if(index == 12){
      return Container(
        width: 89,
        height: 40,
        child: Icon(Icons.waterfall_chart),
      );
    }else {
      return Container(
        width: 89,
        height: 40,
        alignment: Alignment.center,
        decoration: BoxDecoration(
          color: Colors.white,
          border: Border.all(
            width: 0,
            color: ColorsUtil.hexStringColor("#000000", alpha: 0.5),
          ),
        ),
        child: Text(
          index.toString(),
          style: TextStyle(
            fontSize: 16,
          ),
        ),
      );
    }
  }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

半身风雪

感谢打赏,你的鼓励,是我创作的

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值