'getSelectedText on inactive InputConnection flutter

I have this weird problem,When i try to enter value to textfield the keyboard comes up when i try to type the the keyboard goes away , i am also doing fill up Username,Place,mobile that i fetching from sharedprefrence and it's working,but when i try to enter age,height,weight keyboard comes up & goes with in seconds,this is the error/warning i am getting,there is no problem in flutter doctor,

W/IInputConnectionWrapper(23904): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper(23904): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper( 8756): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 8756): endBatchEdit on inactive InputConnection

Code & View

class RegistrationScreenState extends State<RegistrationScreen> {

 TextEditingController mobile = TextEditingController();
  TextEditingController Username = TextEditingController();
  TextEditingController Place = TextEditingController();
  TextEditingController age = TextEditingController();
  TextEditingController height = TextEditingController();
  TextEditingController weight = TextEditingController();

  void initState() {
    getDetails();

  }

  @override
  Widget build(BuildContext context) {
    Size size = MediaQuery
        .of(context)
        .size;
    return Scaffold(
      appBar: AppBar(
        title: Text("Registration", style: TextStyle(color: Colors.black)),
        backgroundColor: Colors.orange,
      ),
      body: SingleChildScrollView(
        child: Stack(
          children: [
            Column(
              children: [
                Container(
                  child: Image.asset('assets/images/gym.png',
                      height: 150,
                      width: double.infinity,
                      fit: BoxFit.fitWidth),
                ),
                SizedBox(
                  height: 50,
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: <Widget>[
                    Expanded(
                      child: Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: TextField(
                          controller: Username,
                          decoration: InputDecoration(
                            prefixIcon: Icon(Icons.perm_identity),
                          ),
                        ),
                      ),
                    ),
                    Expanded(
                      child: Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: TextField(
                          controller: mobile,
                          decoration: InputDecoration(
                            prefixIcon: Icon(Icons.mobile_screen_share),
                          ),
                        ),
                      ),
                    ),
                  ],
                ),
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: Align(
                      alignment: Alignment.centerLeft,
                      child: Text(
                        "User Information",
                        style: TextStyle(
                            fontSize: 15, fontWeight: FontWeight.bold),
                      )),
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: <Widget>[
                    Expanded(
                      child: Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: TextField(
                          controller: Place,
                          decoration: InputDecoration(),
                        ),

                      ),
                    ),
                    Expanded(
                      child: Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: TextField(
                          controller: age,
                          decoration: InputDecoration(
                            hintText: 'Age',
                          ),
                        ),
                      ),
                    ),
                  ],
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: <Widget>[
                    Expanded(
                      child: Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: TextField(
                          controller: height,
                          decoration: InputDecoration(
                            hintText: 'Height(in cm)',
                          ),
                        ),
                      ),
                    ),
                    Expanded(
                      child: Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: TextField(
                          controller: weight,
                          decoration: InputDecoration(
                            hintText: 'Weight(in kg)',
                          ),
                        ),
                      ),
                    ),
                  ],
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }


  //  get & fill Shareprefrece data to textfield
  getDetails() async {
    Future user = SharedPrefrence().getUserMobile();
    Future name = SharedPrefrence().getUserName();
    Future place = SharedPrefrence().getUserPlace();

    user.then((data) async {
      var mobile_no = data;
      setState(() {
        if (mobile_no.isNotEmpty) {
          mobile.text = mobile_no;
        }
        else
          {
            mobile.text = "";
          }
      });
    });

    name.then((data) async {
      var user_name = data;
      setState(() {
        if (user_name.isNotEmpty) {
          Username.text = user_name;
        }
      });
    });

    place.then((data) async {
      var user_place = data;
      setState(() {
        if (user_place.isNotEmpty) {
          Place.text = user_place;
        }
      });
    });
  }



}


Solution 1:[1]

Known issue, tracked here,it's still there. There is no explanation on what's causing it.

I did a little bit of digging. It looks like Android is generating these warnings because we are holding the InputConnection incorrectly in the Engine's TextInputPlugin. I haven't really figured out what we're doing wrong, though.

source

Solution 2:[2]

I am not sure that if this will help you but I was also facing the same issue. I was getting this error when I was using the TextFormField with in Form and the issue was that I created the global form key with in the build method.

class _AddTaskState extends State<AddTask> {
final _formKey = GlobalKey<FormState>(); // <-
String name;
String description;
@override
Widget build(BuildContext context) {
 // first I was using that here.
return Scaffold(

Solution 3:[3]

In my case I had TextFeild in AnimatedSwitcher. The problem was i had key: UniqueKey() inside my widget that containes the TextFeild. So When ever i touched the text feid UniqueKey() gets called and then the widget tree gets regernated.

Solution 4:[4]

If you are using form validator, move your form key out of your build context. This should solve your issue.

Instead of -

class SingInScreen extends StatelessWidget {
final _sigInFormKey = GlobalKey<FormState>();
  @override
  Widget build(BuildContext context) {
    Size size = getRelativeSize(context);

Use this-

`final _sigInFormKey = GlobalKey<FormState>();

class SingInScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    Size size = getRelativeSize(context);`

Solution 5:[5]

I was also getting the same issue when tapping on the TextField.

Use auto focus = true, and issue will be resolved.

TextField( autofocus: true, );

Solution 6:[6]

I "forced" the formatting, in my case for example my form controller was an integer so I did it :

TextFormField(
      controller: _formTextControllers.mycontroller,
      keyboardType: TextInputType.number,
      decoration: InputDecoration(
         labelText: 'label',
      ),
       inputFormatters: [
         **FilteringTextInputFormatter.digitsOnly,**
         MyInputFormatter(),
        ],
      ),

Solution 7:[7]

Try using the textfield methods like onChanged, onSubmitted,... Also try using focus nodes.

Solution 8:[8]

Use FocusScope.of(context).requestFocus(FocusNode());

Solution 9:[9]

So okay I have found a solution for this in my use case. My keyboard used to disappear as soon as it appeared on my screen. This not the bug in the framework, let us understand what happens in the background. When the keyboard pops up, the screen needs to rebuild its components accordingly, so it forces a rebuild. Therefore the entire widgets are re-rendered including the TextFormField or TextField, which closes the Keyboard. To solve this problem, we have to find a way to uniquely identify our widget which is rebuilding, and stop flutter from recreating that widget. This can be done by using keys, first find the parent widget under which our TextFormField/TextField falls, and provide a unique key to it. Remember NOT to initialize the key on the key parameter of the widget. Instead declare it outside the build method and then use it. This makes sure that the unique does not change every time the build method is called. I hope that this helps. Thank You!

Solution 10:[10]

In my case, I had this problem while my array of TextFormFields were children of DataCells of a DataTable which this DataTable was itself child of a ExpansionPanel widget. The problem got fixed when I replaced the parent ExpansionPanelList with a Column and removed the ExpansionPanel widget. I thought that explaining my own case might help somebody with similar issues.

Solution 11:[11]

In my case, I was using a global navigation key for navigation. when I was on an inner page the moment I touch Textfeild or TextFormFeild it pop to the navigation initial root, the problem that cause this problem was I declared the Navigation module inside a Stateless widget. When I changed it to stateful the issue is solved.

Solution 12:[12]

I've been scratching my head over the same issue.

The thing that resolved it for me was removing the media query from within the build method. I guess calling the keyboard messes with this if its running inside the build method and funny things happen.

Size size = MediaQuery
    .of(context)
    .size;

Try doing without it, or passing it into the widget as a static property above the build method