我想问我怎么能改变我的图标的颜色,当我导航到下一页,这意味着当我选择的图标是蓝色的页面,然后图标将保持灰色。我试过setState()
,但它不适合我。
class _CustomBottomNavigationState extends State<CustomBottomNavigation> {
@override
Widget build(BuildContext context) {
final Size size = MediaQuery.of(context).size;
return Container(
width: size.width,
height: 80,
child: Stack(
children: [
CustomPaint(
size: Size(size.width, 80),
painter: BNBCustomPainter(),
),
Center(
heightFactor: 0.6,
child: FloatingActionButton(
onPressed: () {
widget._addingThings(context);
},
backgroundColor: Colors.black,
child: Icon(Icons.add),
elevation:0.1,
),
),
Container(
width: size.width,
height: 80,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
IconButton(icon: Icon(Icons.home), onPressed: () {
Navigator.push(context, PageTransition(type: PageTransitionType.rightToLeft, child: MyScreen(), isIos: true));
}),
IconButton(icon: Icon(Icons.notifications), onPressed: () {
Navigator.push(context, PageTransition(type: PageTransitionType.leftToRight, child: My2Screen()));
}),
Container(width: size.width * 0.2),
IconButton(icon: Icon(Icons.add), onPressed: () {
_pickImageFromCamera();
Navigator.push(context, MaterialPageRoute(builder: (context) => My3Screen()));
}),
IconButton(icon: Icon(Icons.abc), onPressed: () {
Navigator.push(context, PageTransition(type: PageTransitionType.leftToRight, child: My4Screen()));
}),
],
),
)
],
),
);
}
}
2条答案
按热度按时间eulz3vhy1#
您可以为您的图标按钮创建一个自定义小部件,并在该小部件内部维护selected/selected状态。
你可以这样使用它:
643ylb082#
创建变量selectedIndex