You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter TextField点击键盘右下角对勾时onEditingComplete不触发怎么办

问题根因与修复方案

根因1:未指定textInputAction属性

提供的代码未配置textInputAction参数,不同系统的键盘默认动作存在差异,部分场景下右下角对勾按钮被识别为「换行」而非「完成编辑」动作,不会触发onEditingComplete回调。
修复方法:给TextField新增textInputAction: TextInputAction.done配置,明确指定键盘动作类型:

TextField(
  controller: _textEditingController,
  cursorColor: Colors.white70,
  autofocus: true,
  // 新增以下配置
  textInputAction: TextInputAction.done,
  textCapitalization: TextCapitalization.sentences,
  decoration: const InputDecoration(
    fillColor: Color(0xFF616161),
    filled: true,
    contentPadding: EdgeInsets.all(25),
    border: InputBorder.none,
    hintText: 'Enter a title to remember your scan',
    hintStyle: TextStyle(color: Colors.white70),
  ),
  style: const TextStyle(color: Colors.white),
  onEditingComplete: () {
    print('yes');
    // 若需要点击完成后保留输入框焦点,可添加以下代码,覆盖默认释放焦点的逻辑
    // FocusScope.of(context).requestFocus(FocusNode());
  },
)

兼容适配方案

如果修改后仍有部分机型触发异常,可以同时绑定onSubmitted回调,两个回调执行相同逻辑,覆盖所有键盘完成触发场景:

// 统一处理编辑完成逻辑
void _handleEditComplete() {
  print('yes');
}

// TextField新增配置
TextField(
  // 其余原有配置不变
  onEditingComplete: _handleEditComplete,
  onSubmitted: (_) => _handleEditComplete(),
)

内容的提问来源于stack exchange,提问作者dipansh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.27 02:45:04