Flutter:我怎样才能拥有一个多行 TextFormField,它在我按下回车键时不换行,而是执行一个函数?

Flutter: How can I have a multiline TextFormField that doesn't make a new line when I press enter, but executes a function?

我有一个 TextFormField,当我按下 enter 时它会执行一个函数,以提供额外的便利(除了按下按钮时执行的函数)。

当我使 TextFormField 能够有多行(因此它的高度增加)时,回车键不会再导致函数执行,但它只是创建一个新行。

TextFormField(
  validator: (String language) {
    if (value.isEmpty) return 'Please provide a translation in $language.';
    return null;
  },
  autovalidateMode: AutovalidateMode.onUserInteraction,
  controller: _mainControllers[ws],
  textInputAction: TextInputAction.go,
  onFieldSubmitted: (_) => _saveMainTranslation(context),
  //these 2 lines are important
  maxLines: null,
  keyboardType: TextInputType.multiline,
)

“回答你自己的问题”-> 在下面查看我对此问题的解决方案

我要做的就是将最后一行更改为:keyboardType: TextInputType.text.
现在我的 TextFormField 仍然会跳到一个新行,如果文本变大,但如果我按回车,我的功能就会执行。

TextFormField(
  validator: (String language) {
    if (value.isEmpty) return 'Please provide a translation in $language.';
    return null;
  },
  autovalidateMode: AutovalidateMode.onUserInteraction,
  controller: _mainControllers[ws],
  textInputAction: TextInputAction.go,
  onFieldSubmitted: (_) => _saveMainTranslation(context),
  //these 2 lines are important
  maxLines: null,
  keyboardType: TextInputType.text,
)