按钮导航栏

时间:2021-05-29 17:13:49

标签: flutter

我为我的任务应用程序创建了一个暗模式……我通过 ThemeData() 和 switch 实现了它。 所以当我切换到暗模式时,我需要更改底部导航栏的背景颜色。 这是一个缩写代码..

 bool theme = false;

Switch(
   value: theme,
    onChanged: (x) {
    setState(() {
      theme = x;
});
 },
 ),
bottomNavigationBar: BottomNavigationBar(
    unselectedItemColor:theme ? Colors.blueGrey[200] : Colors.blueGrey[900],
    selectedItemColor: theme ? Colors.blueGrey[100] : Colors.white70,
    backgroundColor: theme ? Colors.blueGrey[800] : Color(0xff5B7BA6),

而且颜色一直在变化,但首先我必须点击底部导航栏 那么我应该怎么做才能在不点击底部导航栏的情况下改变颜色??

1 个答案:

答案 0 :(得分:0)

您需要在点击时调用该函数以更改应用程序的模式,以便它在当时调用并更改颜色