【发布时间】:2022-10-12 22:52:56
【问题描述】:
我有一个自定义的底部导航栏,并根据 selectedIndex 成功更改了背景颜色。我通过三元语句来做到这一点:
backgroundColor: selectedIndex == 0
? const Color.fromARGB(255, 0, 52, 35)
: const Color.fromARGB(255, 0, 13, 52),
现在我添加了第三个屏幕,我想按照以下几行设置一个 if 语句:
backgroundColor:
if (selectedIndex == 0)
{const Color.fromARGB(255, 0, 52, 35);}
if (selectedIndex == 1)
{const Color.fromARGB(255, 0, 13, 52);}
if (selectedIndex == 2)
{const Color.fromARGB(255, 87, 0, 54);},
这可能只是一个简单的语法问题——我是 Flutter 的新手。
【问题讨论】:
标签: flutter dart if-statement