问题描述
尝试将光标定位在 TextField
内时,光标手柄会自动消失,并停止拖动。这是显示效果的 gif:
有没有办法阻止这种行为并保持手柄可见(即拖动活动),直到释放鼠标或手指从屏幕上移开?
@override
Widget build(BuildContext context) {
_focusNode.requestFocus();
return TextField(
focusNode: _focusNode,maxLength: 64,expands: false,maxLines: 1,controller: _textEditController,onChanged: _onTextChanged,autocorrect: false,decoration: new Inputdecoration(
border: new OutlineInputBorder(),hintText: "Goal",labelText: "Goal",),);
}
解决方法
您可以使用以下代码。我希望能解决您的问题。
TextFormField(
autovalidateMode: AutovalidateMode.always,maxLength: 64,expands: false,maxLines: 1,controller: _textEditController,autocorrect: false,decoration: new InputDecoration(
border: new OutlineInputBorder(),hintText: "Goal",labelText: "Goal",),onSaved: (String value) {
// This optional block of code can be used to run
// code when the user saves the form.
},validator: (String value) {
return value.contains('@') ? 'Do not use the @ char.' : null;
},)