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

Flutter报错:命名参数‘textTheme’未定义问题咨询

解决Flutter Theme中“The named parameter 'textTheme' isn't defined”报错

从Flutter 2.5版本开始,AppBarTheme类移除了textTheme参数,取而代之的是两个更细分的参数:titleTextStyle(控制AppBar主标题样式)和toolbarTextStyle(控制工具栏内其他文本样式),这就是你遇到报错的原因。

修改你的代码如下即可解决问题:

ThemeData(
  primarySwatch: Colors.blue,
  appBarTheme: const AppBarTheme(
    backgroundColor: Colors.blue,
    // 用titleTextStyle替代原来textTheme里的titleLarge配置
    titleTextStyle: TextStyle(
      fontSize: 20,
      fontWeight: FontWeight.bold,
      color: Colors.white,
    ),
  ),
)

如果需要调整工具栏内其他文本(比如返回按钮旁的辅助文字),可以额外添加toolbarTextStyle参数:

appBarTheme: const AppBarTheme(
  backgroundColor: Colors.blue,
  titleTextStyle: TextStyle(
    fontSize: 20,
    fontWeight: FontWeight.bold,
    color: Colors.white,
  ),
  toolbarTextStyle: TextStyle(
    fontSize: 16,
    color: Colors.white70,
  ),
)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 00:25:57