双击底部导航条项目Flutter

问题描述 投票:0回答:2

在我的主页上,我有一个带有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,
  ),
);
}  
flutter flutter-dependencies
2个回答
0
投票

Inkwell包装您的物品小部件>

BottomNavigationBarItem(
              icon: InkWell(
                onDoubleTap: (){
                      print('click');
                    },
                child: youriconwidget();
              ),
              title: Text(""),
            )

双击时

I/flutter (11516): click

希望有帮助


0
投票

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

Gesture Detector具有您可以使用的onDoubleTap方法。这是您想要做的

© www.soinside.com 2019 - 2024. All rights reserved.