flutter - 颤动底部导航栏图标颜色不变。是某种 setState 错误还是我的代码有问题?
问题描述
我是 Flutter 的新手,实际上我不是编码员,但我正在尝试构建一个可以执行基本操作的应用程序,例如登录页面、注册、用户数据显示在屏幕上,而且我可以从我卡在底部导航栏中的应用程序,我从没想过它会很难通过。
我没有放弃,而是决定四处搜索并得出不同的结果(其中一些很难理解和混淆)。我正在尝试构建一个导航栏,以最少的内存使用(高效代码)路由到不同的页面
我很困惑,我现在不知道该怎么办!请帮助另一个编码器(如果有人解决了这个问题,我会认为自己是编码器,不要想太多)
@override
Widget build(BuildContext context) {
PageController _pageController = PageController();
final List<Widget> _tabs = [FeedPage(), ListingPage(), SettingPage()];
int _selectedIndex = 0;
void _onPageChanged(int index) {
setState(() { //Is something wrong with my setState?
_selectedIndex = index;
});
}
void _onItemTapped(int _selectedIndex) {
_pageController.jumpToPage(_selectedIndex);
}
return Scaffold(
body: PageView(
controller: _pageController,
children: _tabs,
onPageChanged: _onPageChanged, //Check it out
physics: NeverScrollableScrollPhysics(),
),
bottomNavigationBar: BottomNavigationBar(
currentIndex: _selectedIndex, //I use this
onTap: _onItemTapped,
items: [
BottomNavigationBarItem(
icon: Icon(
Icons.home,
),
title: Text("Home"),
),
BottomNavigationBarItem(
icon: Icon(
Icons.list,
),
title: Text("List"),
),
BottomNavigationBarItem(
icon: Icon(
Icons.person,
),
title: Text("Profile"),
),
],
),
);
}
}
//is this the code bugged? or something wrong in my flutter IED or something I am confused
解决方案
试试下面的代码,在脚手架 perntesis 之前插入这段代码,也不要忘记插入包。
bottomNavigationBar: CurvedNavigationBar(
color: Colors.black26,
backgroundColor: Color(0xFFFFC5C5),
buttonBackgroundColor: Colors.greenAccent,
height: 50.0,
animationCurve: Curves.bounceInOut,
items: <Widget>[
Icon(Icons.translate, size: 20, color: Colors.black),
Icon(Icons.translate, size: 20, color: Colors.black),
Icon(Icons.list, size: 20, color: Colors.black),
Icon(Icons.account_balance, size: 20,
color: Colors.black),
// Icon(Icons.camera, size: 20, color: Colors.black),
],
index: 2,
animationDuration: Duration(milliseconds: 400),
onTap: (index) {
debugPrint("Curent index is $index");
}
)
推荐阅读
- django - 在位于 settings.py 的视图中调用函数
- c# - 使用具有通用查询性能的 AsCacheQueryable 从 Ignite 获取数据
- pandas - Pandas 用预定义的值替换单元格值
- javascript - angular8-surveyjs-如何删除默认完成按钮
- r - RShiny - 在“观察”环境中预测值
- vue.js - 使用 vuetify 水平和垂直居中 v-card 的最佳方式
- angular - 替换子组件时能够设置父 div 样式
- create-react-app - ELIFECYCLE 代码 2 eslint 错误与 create-react-library
- python-3.x - 将 Ipywidgets 与数据框一起使用
- python - 仅当 TensorFlow 模型改进了训练和验证数据时才应用梯度下降