1

在此处输入图像描述

如果我长按底部导航栏项目的项目,那么它将显示一个带有项目标题的弹出窗口/吐司(上图中的收件箱弹出窗口)。我想禁用该行为,该怎么做?

这是我当前的底部导航栏

BottomNavigationBar(
        onTap: _selectPage,
        elevation: 2,
        backgroundColor: const Color.fromRGBO(245, 245, 245, 1),
        unselectedItemColor: Colors.grey,
        selectedItemColor: Theme.of(context).primaryColor,
        currentIndex: _selectedPageIndex,
        showSelectedLabels: false,
        showUnselectedLabels: false,
        type: BottomNavigationBarType.fixed,
        items: [
          BottomNavigationBarItem(
            icon: Icon(Icons.home_outlined),
            label: "Home",
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.search),
            label: "Search",
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.add_circle_outline),
            label: "create",
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.notifications_none),
            label: "Inbox",
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.person_outline),
            label: "Profile",
          ),
        ],
      ),
    
4

2 回答 2

5

只需将一个空字符串传递给tooltip它,它就会停止显示弹出窗口。这是您更新的代码:

BottomNavigationBar(
  onTap: _selectPage,
  elevation: 2,
  backgroundColor: const Color.fromRGBO(245, 245, 245, 1),
  unselectedItemColor: Colors.grey,
  selectedItemColor: Theme.of(context).primaryColor,
  currentIndex: _selectedPageIndex,
  showSelectedLabels: false,
  showUnselectedLabels: false,
  type: BottomNavigationBarType.fixed,
  items: [
    BottomNavigationBarItem(
      icon: Icon(Icons.home_outlined),
      label: "Home",
      tooltip: '',
    ),
    BottomNavigationBarItem(
      icon: Icon(Icons.search),
      label: "Search",
      tooltip: '',
    ),
    BottomNavigationBarItem(
      icon: Icon(Icons.add_circle_outline),
      label: "create",
      tooltip: '',
    ),
    BottomNavigationBarItem(
      icon: Icon(Icons.notifications_none),
      label: "Inbox",
      tooltip: '',
    ),
    BottomNavigationBarItem(
      icon: Icon(Icons.person_outline),
      label: "Profile",
      tooltip: '',
    ),
  ],
),

这是几个月前在 github 上提出的问题,请参阅https://github.com/flutter/flutter/issues/71049#:~:text=BottomNavigationBar%20has%20no%20API%20for,to%20completely%20disable %20its%20工具提示

于 2021-05-21T00:36:49.693 回答
0

代替将空字符串设置为工具提示,另一种方法是使用CupertinoTabBar

灵感来自

https://github.com/roughike/inKino/blob/development/mobile/lib/ui/inkino_bottom_bar.dart

PS Flutter 团队的 TooltipWidget 即将推出 https://github.com/flutter/flutter/pull/91609

于 2021-11-12T11:49:54.547 回答