Flutter 跳转到非底部导航栏项关联页面时如何保留导航栏及自定义样式
解决方案
- 跳转非导航栏页面时保持底部导航可见的实现:
persistent_bottom_nav_bar原生支持该特性,跳转时不使用系统默认的Navigator.push方法,改用包内置的pushNewScreen方法,将withNavBar参数设为true即可,示例代码如下:
pushNewScreen( context, screen: 你要跳转的目标页面组件, withNavBar: true, // 保留底部导航栏的核心配置 pageTransitionAnimation: PageTransitionAnimation.cupertino, // 可自选转场动画 );
- 自定义底部导航样式的实现:
包提供了customNavBarWidget参数支持完全自定义导航栏样式,你已经用原生BottomNavigationBar实现的样式代码不需要大幅修改,直接将完整的导航栏组件、悬浮按钮相关配置传入PersistentTabView对应参数即可,核心配置示例如下:
PersistentTabView( context, controller: _tabController, screens: [首页页面, 分类页面, 收藏页面, 我的页面], // 替换为你自己的4个导航页面对应组件 customNavBarWidget: 你已经实现的自定义BottomNavigationBar组件, floatingActionButton: 你已经实现的FloatingActionButton组件, floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, // 其他基础配置项可按需添加 )
提示:自定义导航栏的选中状态直接和 PersistentTabController 的 index 属性绑定即可,不需要单独维护选中状态变量。
内容的提问来源于stack exchange,提问作者Wassef Hassine
相关产品推荐
相关产品推荐

