卡片小部件中条件颜色的颤振问题



我是颤动的新手,并尝试更改我基于多个字符串条件(例如"someText"(创建的SliverList((的Card((颜色。目前,我让 Card(( 根据单个条件更改颜色,但我无法弄清楚如何将多个条件应用于此参数。我想为颜色提供多个字符串条件,如果不满足任何条件,则具有不同的颜色以及默认颜色。任何帮助将不胜感激。

SliverList(
delegate: SliverChildBuilderDelegate(
(context,index) => Card(
color: items[index].theTopic =='someText' ? Colors.greenAccent : Colors.yellow,
child: InkWell(
onTap: () => _navigateToNote(context, items[index]),
customBorder: cardShape,),
childCount: items.length
),
)

您可以在其他部分连续添加条件,无论您需要多少条件。

前任:

color: items[index].theTopic =='someText' ? Colors.greenAccent :  items[index].theTopic =='otherText' ? Colors.amber : items[index].theTopic =='anotherText' ? Colors.red : Colors.black, // last black color will become default color

最新更新