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

Flutter中如何修改TextField上下文菜单的样式?

Flutter上下文菜单样式修改问题及解决方案

我在Flutter应用里的上下文菜单样式效果很差,想要修改它的背景颜色和字体大小,但在ThemeData里配置cardTheme完全没效果,也找不到更多相关信息。

当前上下文菜单样式:
上下文菜单效果

我尝试的无效代码:

return MaterialApp(
  title: 'Martin',
  theme: AppThemes.getLightTheme().copyWith(
    cardTheme: CardTheme(
      color: Colors.pink,
      surfaceTintColor: Colors.green,
      shadowColor: Colors.blue,
    ),
  ),
  initialRoute: RoutesList.splash,
  routes: getRoutes(),
);

解决方案

已找到有效解决方案:修改上下文菜单样式需要在ThemeData中配置textButtonTheme字段。

示例代码:

textButtonTheme: TextButtonThemeData(
  style: TextButton.styleFrom(
    backgroundColor: Colors.white,
    foregroundColor: Colors.white,
    textStyle: customLightTextTheme.displaySmall
        ?.copyWith(color: Colors.black, fontSize: 16.sp),
  ),
)

此方案已解决我的问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 20:12:07