我想去掉在文本字段中按 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,
用容器包裹文本字段。并设置容器高度。
然后在文本字段中设置
expands:true
现在,按 Enter 键时您的文字不会上升
Container(
height: 250, // set the height
child: TextField(
expands: true, // set the expands to true
maxLines: null)
),