美文网首页
flutter TextField内容垂直居中

flutter TextField内容垂直居中

作者: 溪桥星雨 | 来源:发表于2021-06-23 22:01 被阅读0次

有时候TextField内容无法垂直居中,基本骗过测试可以直接使用contentPadding,这个效果在不同的手机上效果不同。所以,不是上策。

完美解决方案:

1.设置TextField有边框,并设置外边框为透明色
2.设置contentPadding:EdgeInsets.only(top: 0, bottom: 0)

在InputDecoration里面设置

                              contentPadding:EdgeInsets.only(top: 0, bottom: 0),
                              border: OutlineInputBorder(
                                borderSide: BorderSide(
                                  color: Colors.transparent,
                                ),
                              ),
                              enabledBorder: OutlineInputBorder(
                                borderSide: BorderSide(
                                  color: Colors.transparent,
                                ),
                              ),
                              disabledBorder: OutlineInputBorder(
                                borderSide: BorderSide(
                                  color: Colors.transparent,
                                ),
                              ),
                              focusedBorder: OutlineInputBorder(
                                borderSide: BorderSide(
                                  color: Colors.transparent,
                                ),
                              ),

相关文章

网友评论

      本文标题:flutter TextField内容垂直居中

      本文链接:https://www.haomeiwen.com/subject/gskiyltx.html