gpt4 book ai didi

dart - Flutter -TextField Controller 在文本之前获取我的光标

转载 作者:行者123 更新时间:2023-12-05 00:53:20 43 4
gpt4 key购买 nike

我在控制台上收到此警告
W/IInputConnectionWrapper(25185): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper(25185): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper(25185): getTextAfterCursor on inactive InputConnection

我正在使用 dateTime 键盘,当我在文本字段中输入文本时,光标会在文本之前移动。这很烦人。我在某处读到需要处置/关闭 TextEditing Controller 。我不确定这意味着什么以及如何。任何人都知道如何消除 TextInputController 上的这些警告和怪异行为。

最佳答案

我有同样的问题,
我的任务
我想在按钮单击时清除我的文本字段

这是我的代码

String searchData = "";
TextEditingController searchEditor = TextEditingController();

Row(
children: <Widget>[
Expanded(
child: TextField( // My textbox
controller: searchEditor,
autofocus: false,
onChanged: (str){
searchData = (str == null)? "" : str;
setState(() {
});
},
decoration: InputDecoration(
prefixIcon: IconTheme(
child: Icon(Icons.search),
data: IconThemeData(color: Colors.blueAccent),
),
labelText: 'Search',
),
),
flex: 8,
),
Expanded(
child: RaisedButton(
color: Basic.hbColor,
textColor: Colors.white,
child: Icon(Icons.clear),
onPressed: (){ // On button click
FocusScope.of(context).unfocus(); // Close keyboard
setState(() {
searchData = "";
});
Future.delayed(Duration(microseconds: 500),(){ //call back after 500 microseconds
searchEditor.clear(); // clear textfield
});
},
elevation: 10,
),
flex: 2,
)
],
)

我解决了 使用'searchEditor.clear();' Future.delayed 内部
因为当我们调用 FocusScope.of(context).unfocus(); 关闭键盘需要几微秒才能关闭,这就是它显示 的原因万宁
getTextBeforeCursor on inactive InputConnection为了克服我叫 searchEditor.clear();几微秒后的方法

这对我有用。

关于dart - Flutter -TextField Controller 在文本之前获取我的光标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51506211/

43 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com