使用按钮 getX 激活文本字段

activate text field using button, getX

如何使用按钮或 GestureDetector 激活 textField 并显示键盘,我已经创建了代码,但是当我第二次单击按钮或 gestureDetector 时,键盘没有显示,textFiled 上的光标是还在

我正在使用 getX

手势检测器

GestureDetector(
      onTap: () {
        FocusScope.of(context).requestFocus(controller.textFieldFocus);
      },
      child: Container(
        // height: 25.0,
        margin: EdgeInsets.symmetric(horizontal: 20.0),
        padding:
            EdgeInsets.only(left: 5.0, right: 240.0, top: 5.0, bottom: 5.0),
        decoration: Ui.getBoxDecoration(
          color: Get.theme.primaryColor,
          border: Border.all(
            color: Color.fromRGBO(149, 151, 161, 1),
            width: 1.0,
          ),
          radius: 14.0,
        ),

        child: Text(
          "reply the comment...",
          style: TextStyle(
            color: Color.fromRGBO(149, 151, 161, 1),
            fontFamily: 'Roboto',
            fontSize: 12,
            letterSpacing: 0,
            fontWeight: FontWeight.normal,
            height: 1,
          ),
        ),
      ),
    );

文本字段

TextField(
                  controller: controller.textEditingController,
                  onSubmitted: (value) {
                    //
                  },
                  focusNode: controller.textFieldFocus, //i using getX
                  style: TextStyle(
                    color: Color.fromRGBO(149, 151, 161, 1),
                    fontFamily: 'Roboto',
                    fontSize: 12,
                    letterSpacing: 0,
                    fontWeight: FontWeight.normal,
                    height: 1,
                  ),
                  autofocus: false,
                  cursorColor: Get.theme.focusColor,
                  decoration: Ui.getInputDecoration(
                    hintText: "add a comment...".tr,
                  ),
                  keyboardType: TextInputType.multiline,
                  maxLines: null,
                  expands: true,
                ),

this Flutter cookbook 文章介绍了如何在点击按钮时将焦点传递给文本字段,应该可以解决您的问题。