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

Flutter SearchDelegate如何移除输入文本下方的下划线和蓝色指示线

Flutter SearchDelegate移除/修改输入框下划线解决方案

你只需要在现有重写的appBarTheme返回的ThemeData中补充inputDecorationTheme配置即可,不需要自定义替换SearchDelegate的输入组件。
修改后的完整代码如下:

@override
ThemeData appBarTheme(BuildContext context) {
  return ThemeData(
    dividerTheme: DividerThemeData(
      color: Colors.white,
    ),
    primaryIconTheme: IconThemeData(color: Colors.white),
    // 新增inputDecorationTheme配置,控制输入框下划线
    inputDecorationTheme: InputDecorationTheme(
      // 移除所有状态下的下划线
      border: InputBorder.none,
      enabledBorder: InputBorder.none,
      focusedBorder: InputBorder.none,
      // 如果需要修改颜色而非移除,就把上面的属性替换成下面的格式,替换为你需要的颜色即可
      // enabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.transparent)),
      // focusedBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.red)),
    ),
    scaffoldBackgroundColor: Colors.white, // 页面背景色
    brightness: Brightness.dark, // 状态栏图标白色显示
    primaryColor: glovar.getColor(farbnr), // 搜索栏背景色
    textSelectionTheme: TextSelectionThemeData(
      cursorColor: Colors.white,
    ), // 光标颜色
  );
}

配置说明

  • 完全移除下划线:将border、enabledBorder、focusedBorder统一设置为InputBorder.none即可,所有状态下都不会显示下划线
  • 仅修改指定状态的下划线颜色:保留边框类型为UnderlineInputBorder,修改borderSide的color参数即可,比如可以设置默认状态下划线透明、聚焦状态显示自定义颜色
  • 如果调整后输入框文字样式不符合预期,可以在ThemeData中补充textTheme配置,titleLarge属性对应SearchDelegate内部输入框的文字样式,示例:textTheme: TextTheme(titleLarge: TextStyle(color: Colors.white, fontSize: 16))

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.10 18:06:03