【发布时间】:2021-05-07 16:43:41
【问题描述】:
我在一个屏幕中使用 Tabbar 和 onGenerateRoute 进行多个视图,而无需更改 AppBar 和 TabBar。
**
这是我的代码(MainScreen 模板)-
**
.....
....
return Scaffold(
appBar: PreferredSize(
preferredSize: Size(_width, 100),
child: AppBar(
automaticallyImplyLeading: false,
backgroundColor: blue,
bottom: PreferredSize(
preferredSize: Size(_width, 40),
child: Stack(
children: [
Center(
child: logoIcon(
75.0,
75.0,
Colors.white,
),
),
Positioned(
right: 15.0,
child: IconButton(
icon: Icon(
Icons.notifications_none,
color: Colors.white,
size: 32.0,
),
onPressed: () {}),
)
],
),
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(
bottom: Radius.circular(50),
),
),
),
),
body: CustomMainBody(
child: Container(
height: _height * 0.90,
width: _width,
child: TabBarView(
controller: _tabController,
children: [
Navigator(
onGenerateRoute: (settings) => MaterialPageRoute(
builder: (context) => HomePage(
changeTabCallBack: (index) => changeTabbar(index)),
settings: settings,
),
),
Navigator(
onGenerateRoute: (settings) => MaterialPageRoute(
builder: (context) => RateComparision(),
settings: settings,
),
),
Navigator(
onGenerateRoute: (settings) => MaterialPageRoute(
builder: (context) => DealOffers(),
settings: settings,
),
),
Navigator(
onGenerateRoute: (settings) => MaterialPageRoute(
builder: (context) => CustomDrawer(
changeTabCallBack: (index) => changeTabbar(index)),
settings: settings,
),
),
],
),
),
),
bottomNavigationBar: Container(
color: blue,
child: TabBar(
indicatorColor: Colors.white,
labelColor: Colors.black,
controller: _tabController,
tabs: [
Tab(
child: Image.asset(
"assets/images/home-nav.png",
color: Colors.white,
height: 26,
width: 26,
),
),
Tab(
child: Image.asset(
"assets/images/rate-nav.png",
color: Colors.white,
height: 26,
width: 26,
),
),
Tab(
child: Image.asset(
"assets/images/OffersNavigation.png",
color: Colors.white,
height: 26,
width: 26,
),
),
Tab(
child: Icon(
Icons.menu,
color: Colors.white,
size: 32.0,
),
),
],
),
),
);
在自定义抽屉页面中,我添加了一个退出项目。但是当我通过注销功能进入登录屏幕时,AppBar和TabBar并没有消失(主屏幕模板留在这里)。
我该如何解决这个问题?
【问题讨论】: