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

Flutter三星A50真机点击TextField报错 SamsungSmartSuggest停止运行

三星Galaxy A50(SM-A505F)Flutter TextField异常修复方案

问题场景

  • 调试环境:三星Galaxy A50(SM-A505F)真机,flutter doctor检测无异常
  • 触发场景:实现含自定义TextField的登录页面时触发三类异常

异常表现

  • 点击TextField唤起软键盘时,控制台立即抛出大量错误
    唤起软键盘报错截图1
    唤起软键盘报错截图2
  • 在TextField中输入内容时,每输入一个字符都会触发一条新报错
    输入内容报错截图
  • 点击软键盘「下一步」按钮(部分场景无需点击),系统弹出「SamsungSmartSuggest... keeps stopping」(三星智能建议服务持续停止运行)提示
    服务停止提示截图1
    服务停止提示截图2

问题关联代码

import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:shopping/core/constants/padding/padding_constants.dart';
import 'package:shopping/core/constants/textstyle/text_styles.dart';
import 'package:shopping/core/init/translations/locale_keys.g.dart';
import 'package:shopping/product/widget/textfield/custom_textfield.dart';

class LoginView extends StatefulWidget {
  const LoginView({Key? key}) : super(key: key);

  @override
  State<LoginView> createState() => _LoginViewState();
}

class _LoginViewState extends State<LoginView> {
  //Controllers
  late final TextEditingController _emailController;
  // FocusNodes
  late final FocusNode _emailFocusNode;
  @override
  void initState() {
    super.initState();

    _emailController = TextEditingController();
    _emailFocusNode = FocusNode();
  }

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Scaffold(
        resizeToAvoidBottomInset: false,
        appBar: AppBar(
          backgroundColor: Colors.transparent,
          elevation: 0,
        ),
        body: Column(
          children: [
            Text(
              LocaleKeys.login.tr(),
              style: TextStylesConstants.titleTextStyle,
            ),
            Padding(
              padding: PaddingConstants.onlyTopSmall,
              child: Text(
                LocaleKeys.addYourDetailsToLogin.tr(),
                style: Theme.of(context).textTheme.subtitle1,
              ),
            ),
            Padding(
              padding: PaddingConstants.onlyTopMedium,
              child: CustomTextField(
                controller: _emailController,
                focusNode: _emailFocusNode,
                keyboardType: TextInputType.emailAddress,
                hintText: LocaleKeys.yourEmail.tr(),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

class CustomTextField extends StatelessWidget {
  const CustomTextField(
      {Key? key, required this.controller, this.focusNode, required this.keyboardType, required this.hintText})
      : super(key: key);
  final TextEditingController controller;
  final FocusNode? focusNode;
  final TextInputType keyboardType;
  final String hintText;

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Container(
        width: context.dynamicWidth(0.9),
        height: context.dynamicHeight(0.069),
        decoration: const BoxDecoration(
          color: ColorConstants.textFieldColor,
          borderRadius: BorderRadius.all(
            Radius.circular(90),
          ),
        ),
        child: Center(
          child: Padding(
            padding: const EdgeInsets.symmetric(horizontal: 24.0),
            child: TextField(
              textInputAction: TextInputAction.next,
              cursorColor: ColorConstants.brightOrange,
              cursorRadius: const Radius.circular(45),
              controller: controller,
              focusNode: focusNode,
              keyboardType: keyboardType,
              decoration: InputDecoration(
                focusedBorder: const OutlineInputBorder(
                  borderSide: BorderSide(color: ColorConstants.textFieldColor),
                ),
                enabledBorder: const UnderlineInputBorder(
                  borderSide: BorderSide(
                    color: ColorConstants.textFieldColor,
                  ),
                ),
                hintText: hintText,
                hintStyle: TextStylesConstants.textFieldTextStyle,
              ),
            ),
          ),
        ),
      ),
    );
  }
}

已尝试参考社区公开issue给出的方案操作,仅修复了三星智能建议服务持续停止运行的问题,其余控制台报错仍存在。

修复方案

1. 修正TextField组件配置冲突

现有自定义TextField存在两处配置问题,会直接触发三星OneUI输入法渲染链路异常:

  • 边框配置不统一:focusedBorder使用OutlineInputBorder、enabledBorder使用UnderlineInputBorder,和外层容器固定圆角、固定高度的样式逻辑冲突。直接禁用TextField自带边框,所有边框样式交由外层Container实现即可:
// 替换原TextField的decoration配置
decoration: InputDecoration(
  border: InputBorder.none,
  focusedBorder: InputBorder.none,
  enabledBorder: InputBorder.none,
  hintText: hintText,
  hintStyle: TextStylesConstants.textFieldTextStyle,
),
  • 光标圆角参数过大:cursorRadius: Radius.circular(45)数值远超输入框实际高度,会触发光标绘制越界报错,调整为匹配输入场景的常规数值即可,例如cursorRadius: const Radius.circular(2)。

2. 屏蔽三星智能建议服务调用

三星自带输入法的智能建议服务和Flutter文本输入通道存在已知兼容问题,给所有TextField追加以下配置,从根源上阻断系统智能建议服务的调用,彻底解决服务崩溃问题:

TextField(
  // 追加以下三项配置
  autocorrect: false,
  enableSuggestions: false,
  autofillHints: null,
  // 保留其余原有配置
  textInputAction: TextInputAction.next,
  cursorColor: ColorConstants.brightOrange,
  // ...其余属性
)

3. 项目环境校验

  • 检查android/app/build.gradle中的minSdkVersion配置,确保数值不低于21,低版本Android会存在文本输入通道兼容缺陷
  • 若当前使用的Flutter稳定版版本低于3.10,升级到3.10及以上版本,该版本线修复了大量三星设备输入法相关的渲染、通道调用bug
  • 重新构建前执行flutter clean清除历史构建缓存,执行flutter pub get拉取依赖后再安装调试

4. 设备端冗余日志处理

完成以上配置后如果仍有不影响功能的系统级日志输出,直接在三星设备设置中关闭三星键盘的「智能建议」「自动拼写检查」「自动补全」功能即可,这类日志属于三星系统服务自身打印,不会影响App实际运行逻辑。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.29 04:57:06