使用案例:您编辑消息的消息应用程序:键盘、闪烁的光标和初始文本出现,但指针(光标)不出现
但是在 Flutter 上,当您使用初始文本(或通过 textController)时,总是有不需要的指针(光标)
示例
重现步骤: 奔跑
flutter create bug
编辑 main.dart 将中心文本(第 100 行)替换为
MyStatefulPage(),
class MyStatefulPage extends StatefulWidget {
@override
State<MyStatefulPage> createState() {
return _MyStatefulPageState();
}
}
class _MyStatefulPageState extends State<MyStatefulPage> {
TextEditingController controller;
@override
void initState() {
super.initState();
controller = new TextEditingController();
controller.text = 'My Initial Text';
}
@override
Widget build(BuildContext context) {
return TextField(
decoration: InputDecoration(
border: InputBorder.none
),
// showCursor: false,
controller: controller,
autofocus: true,
maxLines: 8,
);
}
}
使用该代码,当您打开应用程序键盘时,将会出现,但指针(光标)也会出现,我想隐藏此光标(指针)。
注意:仅适用于Android。
TextField 将enableInteractiveSelection 属性设置为 false 可以解决此问题
在文本表单字段中使用 showCursor: false
TextFormField的cursorHeight: 0和cursorWidth: 0可以隐藏光标。
TextFormField(启用InteractiveSelection:false)
只读:正确, 隐藏光标
您可能需要禁用 TextField。请参阅下面的示例来禁用 Flutter 中的 TextField 输入。
TextField(
decoration: InputDecoration(
labelText: "Your Name (Disabled)",
enabled: false //disabel this text field input
)
),