长按 Flutter 中的底部导航栏项目后如何禁用弹出/吐司?
how to disable a pop up / toast after long press on bottom navigation bar item in Flutter?
如果我长按底部导航栏项目中的某个项目,它会显示一个带有项目标题的弹出窗口/吐司(上图中的收件箱弹出窗口)。我想禁用该行为,该怎么做?
这是我当前的底部导航栏
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",
),
],
),
只需将一个空字符串传递给 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%20tooltips。
不是将空字符串设置为工具提示,而是使用 CupertinoTabBar
灵感来自
https://github.com/roughike/inKino/blob/development/mobile/lib/ui/inkino_bottom_bar.dart
P.S
Flutter 团队即将推出 TooltipWidget
https://github.com/flutter/flutter/pull/91609
如果我长按底部导航栏项目中的某个项目,它会显示一个带有项目标题的弹出窗口/吐司(上图中的收件箱弹出窗口)。我想禁用该行为,该怎么做?
这是我当前的底部导航栏
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",
),
],
),
只需将一个空字符串传递给 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%20tooltips。
不是将空字符串设置为工具提示,而是使用 CupertinoTabBar
灵感来自
https://github.com/roughike/inKino/blob/development/mobile/lib/ui/inkino_bottom_bar.dart
P.S Flutter 团队即将推出 TooltipWidget https://github.com/flutter/flutter/pull/91609