簡體   English   中英

當我在 Flutter 中將文本字段設置為下一行時,文本會上升

[英]When I set the textfield to the next line in Flutter, the text goes up

當我在文本字段中按 Enter 鍵時,我想去掉上升的字母。 我應該怎么辦?

這是代碼的一部分。

Container(
                          child: TextField(
                            textAlign: TextAlign.center,
                            autofocus: true,
                            // controller: myController,
                            onChanged: (value) {
                              // print('$value');
                              setState(() {
                                mainText = value;
                              });
                            },
                            keyboardType: TextInputType.multiline,
                            minLines: 1,
                            maxLines: 10,
                            decoration: InputDecoration(
                              focusedBorder: InputBorder.none,
                              enabledBorder: InputBorder.none,
                              hintText: "짧은 글귀를 집필해주세요",
                              hintStyle:
                                  TextStyle(fontSize: 14, color: Colors.black),
                            ),
                          ),
                        )

根據您的提示文本,您只需要短文本,並且可以通過僅與單行文本字段集成來實現

  Container(
      child: TextField(
        textAlign: TextAlign.center,
        autofocus: true,
        // controller: myController,
        onChanged: (value) {
          setState(() {
            mainText = value;
          });
        },
        keyboardType: TextInputType.text, // this is change
        textInputAction: TextInputAction.done, // this is change
        decoration: InputDecoration(
          focusedBorder: InputBorder.none,
          enabledBorder: InputBorder.none,
          hintText: "짧은 글귀를 집필해주세요",
          hintStyle: TextStyle(fontSize: 14, color: Colors.black),
        ),
      ),
    )

對於多行文本:

keyboardType: TextInputType.multiline,
maxLines: 5,
textInputAction: TextInputAction.newline,

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM