gpt4 book ai didi

flutter 芯片和颜色 - 为什么 ChoiceChip 如此不同

转载 作者:行者123 更新时间:2023-12-05 09:12:41 24 4
gpt4 key购买 nike

假设以下代码

ChipTheme(
data: theme.chipTheme.copyWith(
//labelStyle: TextStyle(color: Colors.black),
secondaryLabelStyle: TextStyle(color: Colors.black),
//selectedColor: Colors.black,
secondarySelectedColor: Colors.grey[300],
//brightness: Brightness.light
),
child:
Row(
children: <Widget>[
Chip(
//selected: currentLevel >= 1,
label: new Text("Level 1"),
avatar: new CircleAvatar(
backgroundColor: Colors.green,
child: Text("1")
),
),
ChoiceChip(
selected: currentLevel >= 2,
label: new Text("Level 2"),
avatar: new CircleAvatar(
backgroundColor: Colors.green,
child: Text("2")
),
),
ChoiceChip(
selected: currentLevel >= 3,
label: new Text("Level 3"),
avatar: new CircleAvatar(
backgroundColor: Colors.green,
child: Text("3")
),
),
],
),
),

这个结果看起来像这样:

enter image description here

第一个是简单的 Chip 小部件。这就是我想要的“选定”ChoiceChip。但正如您所见,第二个芯片与第一个芯片看起来不同。这是为什么?我对第三个未选中的 ChoiceChip 很满意。无论我做什么,我都无法让第二个看起来像第一个,因为 ChoiceChip 似乎使一切变暗(绿色头像和背景颜色)。

所选的 ChoiceChip 甚至看起来都不像被选中或处于事件状态。它看起来几乎是未选中的(第 3 个)。

感谢您提供有关如何正确设置样式的任何提示。

最佳答案

看,解决方案可能会让您感到沮丧。至少在我弄明白之前它让我很沮丧。

ChoceChip 的行为类似于按钮。现在按钮需要一个非空的 onPressed 参数。如果未提供,则呈现按钮的禁用状态。

同样,ChoiceChip 需要一个非空的 onSelected 参数。因此,有效的 ChoiceChip 声明如下所示:

ChoiceChip(
selected: currentLevel >= 2,
label: new Text("Level 2"),
avatar: new CircleAvatar(
backgroundColor: Colors.green,
child: Text("2")
),
onSelected: (value) {}
),

瞧,你有漂亮的 ChoiceChips。

关于flutter 芯片和颜色 - 为什么 ChoiceChip 如此不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57548507/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com