首页 > 解决方案 > 如何在页面向上滚动时隐藏底部导航栏?

问题描述

我已经创建了一个NavigationBar像下面这样的底部,但是当页面向上滚动时我很难隐藏它,如果页面向下滚动则再次显示它。

我在正文和底部导航栏中有一个博客文章列表。我想在帖子列表向上滚动时隐藏底部导航栏,并通过向下滑动动画使其可见。这个怎么做?

向上滚动时隐藏 BottomNavigationBar。这是我的 BottomNavigationBar 代码:

      class _HomePageState extends State<HomePage> {
          bool isSignedIn= false;
          int _CurrentIndex=0;
          int _agentCurrentIndex=0;
          String owneruerID;
          String uploadusertypes;
          List<Widget>_children;
          List<Widget>_agentchildren;
    
          void initState(){
            super.initState();
            GetData();
            uploadusertypes= widget.UserType;
            owneruerID = widget.userID;
            _children=[
              TimeLinePage(tuserID:owneruerID,tUserType:uploadusertypes),
              ManinClass(), //search(),
              UploadPage(UserSID:owneruerID,uploadusertypes:uploadusertypes),
              NotificationsPage(),
              ProfilePage(userProfileID:owneruerID),
            ];
            
              if(FirebaseAuth.instance.currentUser!=null){
                setState(() {
                  isSignedIn= true;
                });
              }else{
                setState(() {
                  isSignedIn= false;
                   });
              }
          }

----------

           @override
      Widget build(BuildContext context) {
        if (isSignedIn) {
          return buildagentScreen();
        }else
         {
          return buildHomeScreen();
        }
      }

----------

    Scaffold buildHomeScreen(){
          return Scaffold(
              backgroundColor: Colors.black,
              body: _children[_CurrentIndex],
              bottomNavigationBar: CupertinoTabBar(
                currentIndex: _CurrentIndex,
                backgroundColor: Colors.black,
                onTap: onTabchangePage,
                activeColor: Colors.green,
                inactiveColor: Colors.white,
                items: [
                  BottomNavigationBarItem(icon:Icon(Icons.home),title: Text('home'),),
                  BottomNavigationBarItem(icon:Icon(Icons.search)),
                  BottomNavigationBarItem(icon:Icon(Icons.photo_camera,size: 40,)),
                  BottomNavigationBarItem(icon:Icon(Icons.notifications)),
                  BottomNavigationBarItem(icon:Icon(Icons.person_add_alt_1_sharp)),
                ],
              ),
            );
        }

标签: flutter

解决方案


推荐阅读