【问题标题】:Set Flutter bottomNavigationBar inactive设置 Flutter bottomNavigationBar 不活动
【发布时间】:2018-11-02 15:05:36
【问题描述】:

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

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 但它的所有项目都不应该处于活动状态。

将 currentIndex 设置为不存在的索引时,我得到了预期的错误。

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

提前谢谢你。

【问题讨论】:

  • 那么,您检查了答案,找到了您想要的吗?

标签: flutter flutter-layout


【解决方案1】:

你可以试试

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')
      ),
...

【讨论】:

  • 你能解释一下这会做什么以及为什么吗?
  • @codeboi - 用于根据 isInactive 值显示来自资产的不同图标
猜你喜欢
  • 2022-11-18
  • 2021-07-27
  • 2019-06-09
  • 2020-07-29
  • 1970-01-01
  • 2019-05-24
  • 2019-02-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多