Flutter:如何在文本字段上隐藏光标的 "belly"
Flutter: how to hide Cursor's "belly" on textfield
每当用户单击文本字段以更改它时,光标就会出现,所以它就是所谓的“肚皮”(我不知道它实际上叫什么,见下图 - 红色箭头)。我想启用交互式选择(即允许将光标移动到文本字段旁边),并在编辑时显示闪烁的光标,但我不希望出现所谓的光标。
这是我的代码:
TextField(
enableInteractiveSelection: true,
showCursor: true,
autofocus: false,
decoration: InputDecoration(
isDense: true,
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.grey),
borderRadius: BorderRadius.all(Radius.circular(30))
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.grey),
borderRadius: BorderRadius.all(Radius.circular(30))
),
),
onChanged: (text) => {},
textAlign: TextAlign.center,
controller: _firstNameChanged
? (_firstNameController..text = _newFirstName)
: (_firstNameController..text = userRep.firstName),
inputFormatters: [
FilteringTextInputFormatter.allow(RegExp('[a-zA-Z]'))
],
focusNode: _firstNameInputFocusNode,
onSubmitted: (text) {
if(text.isNotEmpty) {
setState(() {
_newFirstName = text;
_firstNameChanged = true;
});
}
},
style: GoogleFonts.lato(
fontSize: 16.0,
color: Colors.black,
)
)
有什么想法吗?
感谢@Dude 的评论,我终于按照this answer.
解决了这个问题
完整代码:
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
textSelectionHandleColor: Colors.transparent, /// <- Added
cursorColor: Colors.lightGreen[800],
primaryColor: Colors.green,
accentColor: Colors.lightGreen[800],
fontFamily: 'NewRomanTimes',
textTheme: TextTheme(
headline1: TextStyle(fontSize: 72.0, fontWeight: FontWeight.bold),
headline6: TextStyle(fontSize: 36.0, fontStyle: FontStyle.italic),
)
),
home: MyHomePage()
);
}
每当用户单击文本字段以更改它时,光标就会出现,所以它就是所谓的“肚皮”(我不知道它实际上叫什么,见下图 - 红色箭头)。我想启用交互式选择(即允许将光标移动到文本字段旁边),并在编辑时显示闪烁的光标,但我不希望出现所谓的光标。
这是我的代码:
TextField(
enableInteractiveSelection: true,
showCursor: true,
autofocus: false,
decoration: InputDecoration(
isDense: true,
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.grey),
borderRadius: BorderRadius.all(Radius.circular(30))
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.grey),
borderRadius: BorderRadius.all(Radius.circular(30))
),
),
onChanged: (text) => {},
textAlign: TextAlign.center,
controller: _firstNameChanged
? (_firstNameController..text = _newFirstName)
: (_firstNameController..text = userRep.firstName),
inputFormatters: [
FilteringTextInputFormatter.allow(RegExp('[a-zA-Z]'))
],
focusNode: _firstNameInputFocusNode,
onSubmitted: (text) {
if(text.isNotEmpty) {
setState(() {
_newFirstName = text;
_firstNameChanged = true;
});
}
},
style: GoogleFonts.lato(
fontSize: 16.0,
color: Colors.black,
)
)
有什么想法吗?
感谢@Dude 的评论,我终于按照this answer.
解决了这个问题完整代码:
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
textSelectionHandleColor: Colors.transparent, /// <- Added
cursorColor: Colors.lightGreen[800],
primaryColor: Colors.green,
accentColor: Colors.lightGreen[800],
fontFamily: 'NewRomanTimes',
textTheme: TextTheme(
headline1: TextStyle(fontSize: 72.0, fontWeight: FontWeight.bold),
headline6: TextStyle(fontSize: 36.0, fontStyle: FontStyle.italic),
)
),
home: MyHomePage()
);
}