疑難雜癥1:Flutter中TextField的hintText不居中與光標(biāo)位置不一致

提供幾種解決方式,總用一種適合你!

方法一:在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之后高度就固定了

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容