gpt4 book ai didi

flutter - 双击底部导航栏项目 Flutter

转载 作者:行者123 更新时间:2023-12-02 19:44:48 31 4
gpt4 key购买 nike

在我的主页中,我有一个带有 2 个菜单的底部导航。

我有源库 bottomNavigationBar: BottomNavigationBar

在原始库中没有属性onDoubleTap

有没有什么技术可以用它来实现。

这是我现在做的

List<Widget> _widgetOptions;
int _selectedIndex = 0;
@override
void initState() {
super.initState();
_widgetOptions = <Widget>[
HomeScreen(),
SettingScreen();
];
}
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: IndexedStack(
children: _widgetOptions,
index: _selectedIndex,
),
bottomNavigationBar: BottomNavigationBar(
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Image.asset("assets/icons/home.png",
),
activeIcon: Image.asset(
"assets/icons/home_active.png",
),
),
BottomNavigationBarItem(
icon: Image.asset(
"assets/icons/service.png",
),
activeIcon: Image.asset(
"assets/icons/service.png",
),
),
],
currentIndex: _selectedIndex,
onTap: _onItemTapped,
),
);
}

最佳答案

您可以使用 GestureDetector 小部件并将其包裹在您在 bottomNavigationBar 属性中传递的 BottomNavigationBar

Gesture Detector 有一个 onDoubleTap 方法,可用于您的情况。这是你想要做的

          bottomNavigationBar: GestureDetector(
onDoubleTap: (){
//execute Event
},
child: BottomNavigationBar(
items: [...],
),

关于flutter - 双击底部导航栏项目 Flutter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59485090/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com