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
相关产品推荐
相关产品推荐

