Flutter TextField 多行文本 文本域 點(diǎn)擊區(qū)域只有一行問題

Flutter TextField 多行文本 文本域 點(diǎn)擊區(qū)域只有一行問題,只有點(diǎn)擊第一行才會(huì)彈出鍵盤
找了半天資料沒找到,只能自己調(diào)試,幸好終于找出來了。

我定義的高度是350高度,正常我們需要的是 TextField 直接鋪滿整個(gè)350高度,但由于我設(shè)置了 minLines最小行是1,所以 TextField 沒有跟多內(nèi)容撐開就導(dǎo)致TextField 的點(diǎn)擊區(qū)域只有一行。

在多行文本情況下

  • minLines單獨(dú)使用,不設(shè)置maxLines(默認(rèn)是1),只要大于1就會(huì)報(bào)錯(cuò)
  • maxLines單獨(dú)使用,不設(shè)置minLines(默認(rèn)是null),maxLines多少,點(diǎn)擊區(qū)域就有多少行
  • minLines和maxLines同時(shí)使用的話可以根據(jù)內(nèi)容自適應(yīng)最小行數(shù)到最高行數(shù)

解決辦法就是不設(shè)置minLines,把maxLines設(shè)置大一點(diǎn)就行,根據(jù)實(shí)際情況調(diào)整就行。

代碼

Widget getTextField({
    TextEditingController controller,
    TextInputType keyboardType: TextInputType.multiline,
    TextInputAction textInputAction: TextInputAction.next,
    FocusNode focusNode,
    String hintText,
    int length: 32,
  }) {
    return Container(
      width: double.infinity,
      padding: EdgeInsets.symmetric(
        vertical: setWidth(10),
        horizontal: setWidth(20),
      ),
      height: setHeight(350),
      alignment: Alignment.topCenter,
      child: TextField(
        controller: controller,
        focusNode: focusNode,
        maxLines: 20,
        textInputAction: textInputAction,
        keyboardType: keyboardType,
        textAlign: TextAlign.left,
        style: TextStyle(fontSize: setSp(26)),
        inputFormatters: <TextInputFormatter>[
          LengthLimitingTextInputFormatter(length),
        ],
        decoration: InputDecoration(
          hintText: hintText,
          hintStyle: TextStyle(fontSize: setSp(26), color: XColors.textColor3),
          isDense: true,
          contentPadding: EdgeInsets.only(
            left: setWidth(0),
            top: setHeight(0),
            bottom: setHeight(4),
            right: setWidth(0),
          ),
          border: InputBorder.none,
        ),
      ),
      decoration: BoxDecoration(
        color: XColors.dividerColor,
        border: Border.all(color: XColors.grayColor2, width: setWidth(2)),
        borderRadius: BorderRadius.circular(setWidth(10)),
      ),
    );
  }
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

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