首页 > 解决方案 > 尝试将样式主题添加到 BottomNavigationBarItem 中的标题时,我收到“无效的常量值”

问题描述

我在 BottomNavigationBarItem 的标题中添加了一个主题,我收到错误“无效的常量值”。

我知道这不是我正在使用的主题类型,因为我能够分解我的主题方法并在下一个 BottomNavigationBarItem 中使用各个常量。嗯,我打算张贴一张照片,显示我在这里的意思,但我想我还不能。

这是告诉我我有无效常量值的代码

BottomNavigationBarItem(
            icon: Icon(CustomIcons.wrestlingring2),
            title: Text('Event', style: Theme.of(context).textTheme.button),
          ),

这段代码是我在样式页面中的 buttonTheme 方法中直接将 const 值添加到样式的地方

BottomNavigationBarItem(
            icon: Icon(CustomIcons.wrestling),
            title: Text('Match Details', style: TextStyle(fontFamily: montserratFont, fontSize: smallTextSize, color: textColorLight)),
          ),

这是样式页面中的常量值和按钮主题

const smallTextSize = 14.0;
const Color buttonTextColour = Color(0xffdc0000);
const String montserratFont = 'Montserrat';

const buttonTextStyle = TextStyle(
  fontFamily: montserratFont,
  fontSize: buttonTextSize,
  color: textColorLight,
);

我注意到在颤振代码中,BottomNavigationBarItem 是一个常量,并认为这可能是问题所在

const BottomNavigationBarItem({
    @required this.icon,
    this.title,
    Widget activeIcon,
    this.backgroundColor,
  }) : activeIcon = activeIcon ?? icon,
       assert(icon != null);

但后来我注意到 RaisedButton 也是如此,但它不受我添加主题的影响。

const RaisedButton({
    Key key,
    @required VoidCallback onPressed,
    ValueChanged<bool> onHighlightChanged,
    ButtonTextTheme textTheme,

如果有另一种方法可以在 NavigationBarItem 中使用带有标题的主题,如果有人能指出来,我将不胜感激。我宁愿不必为整个 ButtomNavigationBar 设置主题。

标签: flutter

解决方案


推荐阅读