提供幾種解決方式,總用一種適合你!
方法一:在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ù)。
簡單來說,就類似于Word中的倍體一樣, height 的值乘以fontSize為實(shí)際行高。
style: TextStyle(
height: 1,
textBaseline: TextBaseline.alphabetic,
fontSize: 25,
)
我在開發(fā)中, 遇到初次渲染時光標(biāo)‘主文本’ 和hint '提示文本'沒有對齊, 重新打開頁面就對齊了, 實(shí)際測量發(fā)現(xiàn)inport高度兩次測量不一致,當(dāng)設(shè)置height之后高度就固定了