利用组件ColorFiltered的滤镜效果实现。
在main入口的build使用ColorFiltered包裹设置颜色值,如果不用灰色主题就不包裹,用个布尔值控制是否包裹。
@override Widget build(BuildContext context) {return showGreyMode///灰色主题模式? ColorFiltered(colorFilter: const ColorFilter.matrix(<double>[0.2126,0.7152,0.0722,0,0,0.2126,0.7152,0.0722,0,0,0.2126,0.7152,0.0722,0,0,0,0,0,1,0,]),child: Scaffold(body: IndexedStack(children: mainLogic.body,index: mainLogic.selectedIndex,),bottomNavigationBar: BottomNavigationBar(//设置底部按钮排序样式type: BottomNavigationBarType.fixed,//设置点击状态颜色fixedColor: Colors.red,//设置没有被点击到状态颜色unselectedItemColor: Colors.black,//底部按钮集合items: mainLogic.getItems,onTap: (int index) {setState(() {mainLogic.selectedIndex = index;});},currentIndex: mainLogic.selectedIndex,),),)///正常主题模式: Scaffold(body: IndexedStack(children: mainLogic.body,index: mainLogic.selectedIndex,),bottomNavigationBar: BottomNavigationBar(//设置底部按钮排序样式type: BottomNavigationBarType.fixed,//设置点击状态颜色fixedColor: Colors.red,//设置没有被点击到状态颜色unselectedItemColor: Colors.black,//底部按钮集合items: mainLogic.getItems,onTap: (int index) {setState(() {mainLogic.selectedIndex = index;});},currentIndex: mainLogic.selectedIndex,),); }