在使用TextFeild时,当我们设置了高度,看到的TextFeild内容并不能居中,那如何做到真正的居中呢?
很多人会使用
contentPadding: EdgeInsets.all(0)
的方式,但在部分小屏手机上还是会出现不居中的情况。
还有通过
textBaseline: TextBaseline.alphabetic
来实现,发现并没有达到理想的效果。
这里推荐一种确实有效的方法:
border: OutlineInputBorder(borderSide: BorderSide.none),
主要在于
1.border 不能直接使用InputBorder.none
2.如果文字偏上用TextAlignVertical.bottom修正
3.旧版本的flutter可能需要设置 contentPadding: EdgeInsets.all(0),