如何在Flutter中通过弯曲的导航栏导航不同的页面? [英] how to navigate different pages by curved navigation bar in flutter?
本文介绍了如何在Flutter中通过弯曲的导航栏导航不同的页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法在颤动中使用弯曲的导航栏,当我滑动屏幕时,弯曲的导航栏的按钮也会移动,但是当我点击弯曲的导航栏的按钮时,什么也没有发生.我认为 onTap()无法正常工作.当我点击按钮时如何浏览页面? 这是我程序的代码=>
i can't able to use curved navigation bar in flutter, when i slide screen so buttons of curved navigation bar are also moving but when i tap on buttons of curved navigation bar nothing happens . i think onTap() didn't work properly. how to navigate pages when i tap buttons? here is the code of my program=>
static final String id = 'profile_page';
@override
_PagesState createState() => _PagesState();
}
class _PagesState extends State<Pages> {
PageController _pageController;
int _Page=0;
@override
void initState() {
super.initState();
_pageController = PageController();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: PageView(
controller: _pageController,
children: <Widget>[
Search(),
Trending(),
Friends(),
Profile(),
],
onPageChanged: (int index) {
setState(() {
_pageController.jumpToPage(index);
});
}
),
bottomNavigationBar: CurvedNavigationBar(
animationCurve: Curves.easeInOutBack,
index:3,
items: <Widget>[
Icon(Icons.search, size: 30, color: Colors.white, ),
Icon(Icons.trending_up, size: 30, color: Colors.white),
Icon(Icons.group, size: 30, color: Colors.white),
Icon(Icons.person, size: 30, color: Colors.white)
],
color: Colors.blueAccent,
backgroundColor: Colors.white,
height: 60.0,
onTap: (int index) {
setState(() {
_pageController.jumpToPage(index);
});
},
),
);
}
}
推荐答案
只需替换
_pageController = PageController();
和
final _pageController = PageController();
并在 void initState()方法中删除_pageController = PageController();
.
不使用int _Page=0;
您会没事的.
这篇关于如何在Flutter中通过弯曲的导航栏导航不同的页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文