【问题标题】:Bottom navigation bar buttons don't work flutter底部导航栏按钮不起作用
【发布时间】:2020-09-15 11:13:53
【问题描述】:

我在我的颤振应用程序中使用了这个包https://pub.dev/packages/google_nav_bar,当我尝试将 onPressed 函数添加到我的按钮以重定向到新 UI 时,它不起作用。就像我只是单击并没有任何反应,这是我从包中添加到示例代码中的内容

  GButton(
                            icon: Icons.favorite,
                            text: 'Saved',
                            onPressed: () {
                              Navigator.push(
                                  context,
                                  MaterialPageRoute(
                                      builder: (_) => FavoriteProviders()));
                            },
                          ),
  GButton(
                    icon: Icons.send,
                    text: 'Messages',
                    onPressed: () {
                      Navigator.push(
                          context,
                          new MaterialPageRoute(
                              builder: (_) => MessageList()));
                    },
                  ),
                ],
                selectedIndex: _selectedIndex,
                onTabChange: (index) {
                  setState(() {
                    _selectedIndex = index;
                  });
                }),
          ),

【问题讨论】:

    标签: flutter


    【解决方案1】:

    试试这个插件Presistant_bottom_nav_bar.现在我可以在每个屏幕上使用底部导航栏 还具有 15 多种风格的底部导航栏变体

    PersistentTabController _controller =PersistentTabController(initialIndex: 0);
    
    //Screens for each nav items.import Class your Views
      List<Widget> _NavScreens() {
        return [
         FavoriteProviders(),
         MessageList(),
         Container(color: Colors.green);
         Container(color: Colors.red);
         Container(color: Colors.yellow);
          
        ];
      }
    
    
      List<PersistentBottomNavBarItem> _navBarsItems() {
        return [
          PersistentBottomNavBarItem(
           icon: Icon(Icons.favorite),
            title: ("Saved"),
            activeColor: CupertinoColors.activeBlue,
            inactiveColor: CupertinoColors.systemGrey,
          ),
          PersistentBottomNavBarItem(
            icon: Icon(Icons.send),
            title: ("Messages"),
            activeColor: CupertinoColors.activeGreen,
            inactiveColor: CupertinoColors.systemGrey,
          ),
          PersistentBottomNavBarItem(
            icon: Icon(Icons.person_pin),
            title: ("Help"),
            activeColor: CupertinoColors.systemRed,
            inactiveColor: CupertinoColors.systemGrey,
          ),
          PersistentBottomNavBarItem(
            icon: Icon(Icons.local_activity),
            title: ("ProfileScreen"),
            activeColor: CupertinoColors.systemIndigo,
            inactiveColor: CupertinoColors.systemGrey,
          ),
          PersistentBottomNavBarItem(
            icon: Icon(Icons.local_activity),
            title: ("Demo"),
            activeColor: CupertinoColors.systemIndigo,
            inactiveColor: CupertinoColors.systemGrey,
          ),
    
        ];
      }
    @override
    Widget build(BuildContext context) {
        return Center(
          child: PersistentTabView(
            controller: _controller,
            screens: _NavScreens(),
            items: _navBarsItems(),
            confineInSafeArea: true,
            backgroundColor: Colors.white,
            handleAndroidBackButtonPress: true,
            resizeToAvoidBottomInset: true,
            hideNavigationBarWhenKeyboardShows: true,
            popAllScreensOnTapOfSelectedTab: true,
            navBarStyle: NavBarStyle.style9,
          ),
        );
    }
    

    【讨论】:

    • 我已经更新了答案,如果对你有用,请告诉我,如果没有用试过的代码更新问题@sanda17
    • 我希望当您触摸时被重定向到新 UI,而不是在其他 UI 中打开 Ui
    • 我不明白..@sanda17
    • 我不明白..你的意思是“重定向到新 UI 而不是在另一个 UI 中打开 Ui”@sanda17
    • 我希望按钮打开一个新的 UI,而不是让我的第一个 UI 在后台
    猜你喜欢
    • 2022-01-18
    • 2020-05-15
    • 1970-01-01
    • 1970-01-01
    • 2017-12-14
    • 2020-01-29
    • 1970-01-01
    • 2015-04-09
    • 1970-01-01
    相关资源
    最近更新 更多