Flutter - 更改 SVG 图标颜色

时间:2021-05-18 14:52:09

标签: flutter dart svg

我有一个 Flutter 应用,它有一个 BottomNavigationBar,它的图标是用 svg 制作的。从该栏中选择图标时,只有文本会改变颜色,svg 图标颜色保持不变。

bottomNavigationBar: BottomNavigationBar(
        selectedItemColor: widget._colors.orange,
        unselectedItemColor: widget._colors.grey,
        items: _iconNavBar,
        currentIndex: _index,
        type: BottomNavigationBarType.fixed,
        onTap: onTap,
      ),

BottomNavigationBarItem() 行为示例

BottomNavigationBarItem(
    icon: SvgPicture.asset(
      'svgs/home.svg',
    ),
    label: 'Home')

1 个答案:

答案 0 :(得分:0)

只需尝试在 activeIcon: 中使用 bottomBarItem,然后将默认图标与 color 一起放置。 示例:

BottomNavigationBarItem(
              label: 'label',
              icon: SvgPicture.asset(
                  iconPath,
              ),
              activeIcon: SvgPicture.asset(
                  iconPath,
                  color: Colors.blue,
              ),
            ),
相关问题