本文介绍了将Flutter bottomNavigationBar设置为不活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有底部导航栏的应用程序:

I'm having an app with a bottom navigation bar:

BottomNavigationBar(
 type: BottomNavigationBarType.fixed,
 items: [

   BottomNavigationBarItem(
    icon: Image.asset('assets/icons/inactive/sth.png'),
    activeIcon: Image.asset('assets/icons/active/sth.png'),
    title: Text('Sth')
   ),

   BottomNavigationBarItem(
    icon: Image.asset('assets/icons/inactive/sth.png'),
    activeIcon: Image.asset('assets/icons/active/sth.png'),
    title: Text('Sth')
   ),

  ],
  onTap: (int index) {
    _currentIndex = index;
  },
  currentIndex: _currentIndex
)

现在,我有一些用例,我想显示bottomNavigationBar,但其中的任何一项都不应该处于活动状态.

Now I have some use cases where I want to display the bottomNavigationBar but none of its items should be active.

将currentIndex设置为不存在的索引时,出现了预期的错误.

When setting the currentIndex to a non-existing index, I'm getting an error as expected.

有什么办法可以实现我的目标?

Is there any way to achieve my goal?

谢谢.

推荐答案

您可以尝试类似

bool isInactive;
BottomNavigationBar(
    type: BottomNavigationBarType.fixed,
    items: [

      BottomNavigationBarItem(
          icon: Image.asset('assets/icons/inactive/sth.png'),
          activeIcon: isInactive ? Image.asset('assets/icons/active/sth.png') : Image.asset('assets/icons/inactive/sth.png'),
          title: Text('Sth')
      ),
...

这篇关于将Flutter bottomNavigationBar设置为不活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 17:44