提供幾種解決方式旱幼,總用一種適合你虏辫!
方法一:在main.dart里全局修改
theme: ThemeData(
textTheme: TextTheme(subhead: TextStyle(textBaseline: TextBaseline.alphabetic))
)
方法二:在文件中單獨(dú)修改
TextField(
style: TextStyle(textBaseline: TextBaseline.alphabetic),
)
方法三:設(shè)置 locale: Locale('en', 'US'),
和isCollapsed: true,
InputDecoration(
isCollapsed: true,
hintStyle: TextStyle(
locale: Locale('en', 'US'),
),
)
方法四:
如下設(shè)置:
1.設(shè)置textField
有邊框甚垦,并設(shè)置外邊框?yàn)橥该魃?br>
2.設(shè)置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,
),
),
方法五:設(shè)置‘行高’
先看下介紹:The height of this text span, as a multiple of the font size.
意思就是:此文本跨度的高度蜗帜,作為字體大小的倍數(shù)来惧。
簡(jiǎn)單來(lái)說(shuō)洽蛀,就類似于Word中的倍體一樣耙蔑, height
的值乘以fontSize
為實(shí)際行高见妒。
style: TextStyle(
height: 1,
textBaseline: TextBaseline.alphabetic,
fontSize: 25,
)
我在開(kāi)發(fā)中, 遇到初次渲染時(shí)光標(biāo)‘主文本’ 和hint '提示文本'沒(méi)有對(duì)齊甸陌, 重新打開(kāi)頁(yè)面就對(duì)齊了须揣, 實(shí)際測(cè)量發(fā)現(xiàn)inport高度兩次測(cè)量不一致盐股,當(dāng)設(shè)置height
之后高度就固定了