我正在使用底部导航栏和页面视图,因此要在页面之间进行切换,我可以点击Navigationa栏,然后向左或向右滑动,但是问题是,当点击导航栏时,页面状态会更新,我不希望它发生,这是我的代码:
Scaffold(
body: PageView(
controller: pageController,
onPageChanged: _pageSwipped,
children: <Widget>[
Search(),
Chat(),
Profile(),
],
),
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.shifting,
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.search),
label: Lang.getString(context, "search"),
),
BottomNavigationBarItem(
icon: Icon(Icons.chat_outlined),
label: Lang.getString(context, "chats"),
),
BottomNavigationBarItem(
icon: Icon(Icons.account_circle),
label: Lang.getString(context, "profile"),
),
],
currentIndex: _currenIndex,
selectedItemColor: Colors.blue,
iconSize: _deviceSize.size.height * 0.046,
selectedFontSize: _deviceSize.size.height * 0.023,
unselectedItemColor: Colors.grey,
onTap: _bottomTapped,
),
);
我尝试使用IndexedStack,并在单击导航栏时保持页面状态,但是我想包括左右滑动页面,这是代码:
Scaffold(
body: IndexedStack(
index: _currenIndex,
children: <Widget>[
Search(),
Chat(),
Profile(),
],
),
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.shifting,
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.list_alt),
label: Lang.getString(context, "my_rides")),
BottomNavigationBarItem(
icon: Icon(Icons.drive_eta),
label: Lang.getString(context, "add_ride"),
),
BottomNavigationBarItem(
icon: Icon(Icons.search),
label: Lang.getString(context, "search"),
),
BottomNavigationBarItem(
icon: Icon(Icons.chat_outlined),
label: Lang.getString(context, "chats"),
),
BottomNavigationBarItem(
icon: Icon(Icons.account_circle),
label: Lang.getString(context, "profile"),
),
],
currentIndex: _currenIndex,
selectedItemColor: Colors.blue,
iconSize: _deviceSize.size.height * 0.046,
selectedFontSize: _deviceSize.size.height * 0.023,
unselectedItemColor: Colors.grey,
onTap: _bottomTapped,
),
);
更改页面时如何实现底部导航栏和左右滑动页面而不更新页面状态。