6

I get this warnings on my Console W/IInputConnectionWrapper(25185): getTextBeforeCursor on inactive InputConnection W/IInputConnectionWrapper(25185): getSelectedText on inactive InputConnection W/IInputConnectionWrapper(25185): getTextAfterCursor on inactive InputConnection

I am using dateTime keyboard, when I enter text in textfield the cursor moves before the Text. This is annoying. I read somewhere that the TextEditing controller needs to be disposed/ closed. I am not sure how and what does that mean. Any one knows how to do away with these warnings and weird behavior on the TextInputController.

4

3 回答 3

2

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

这是我的代码

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(); 关闭键盘需要几微秒才能关闭,这就是为什么它显示这个WANRINGgetTextBeforeCursor on inactive InputConnection 克服我调用 searchEditor.clear(); 几微秒后的方法

这对我有用。

于 2019-11-26T08:28:35.603 回答
0

您必须在按下按钮之前最小化/关闭键盘,如果这样做,您将不会收到任何警告。

于 2019-10-21T06:14:08.247 回答
-2

你需要先创建变量

<<< var _controller = TextEditingController(); >>>

然后你创建文本字段的属性并传递它

<<<controller: _controller,>>>

然后当你的事情完成时

<<<_controller.clear();>>>
于 2020-05-07T01:57:10.680 回答