尝试在BottomNavigationBarItem中为标题添加样式主题时收到“无效的常量值”

时间:2019-10-27 03:16:22

标签: flutter

我在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)),
          ),

这是样式页面中的常量值和buttonTheme

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设置主题。

0 个答案:

没有答案