Keyboard dismissed and Multiline issue after clicking enter in flutter

Issue

I am trying to create app that enables user to type only on doubleTap() using multiline TextFormField. So, I am using InkWell but after writing when user click the enter wont’t goes to new line. Please check out this simple func.

getTextFormFieldWithInkwell() {
return Container(
  height: 200,
  width: 200,
  child: InkWell(
    onTap: () {
      print("onTap");
    },
    onDoubleTap: () {
      // some func that enables user to write text
      print("onTap");
    },
    child: TextFormField(
      keyboardType: TextInputType.multiline,
      maxLines: 10,
      textInputAction: TextInputAction.newline,
      onChanged: (String t) {
        print("onChanged");
        print(t);
      },
    ),
  ),
);
}

Similar open issue in GITHUB

Solution

Replace InkWell with TapGesture will solve this issue.

 getTextFormFieldWithInkwell() {
  return Center(
    child: Container(
      height: 400,
      width: 400,
      child: GestureDetector(
        onTap: () {
          print("onTap");
        },
        child: TextFormField(
          controller: controller1,
          keyboardType: TextInputType.multiline,
          maxLines: 10,
          textInputAction: TextInputAction.newline,
          onChanged: (String t) {
            print("onChanged");
            print(t);
          },
        ),
      ),
    ),
  );
}

Answered By – jazzbpn

Answer Checked By – Clifford M. (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *