gpt4 book ai didi

dart - Flutter 复选框类 : When I tick a card, 所有其他的也都被选中

转载 作者:IT王子 更新时间:2023-10-29 06:51:50 25 4
gpt4 key购买 nike

  bool selected = false;

new Card(
shape: selected
? new RoundedRectangleBorder(
side: new BorderSide(color: Colors.blue, width: 2.0),
borderRadius: BorderRadius.circular(4.0))
: new RoundedRectangleBorder(
side: new BorderSide(color: Colors.white, width: 2.0),
borderRadius: BorderRadius.circular(4.0)),

child: new Row(


mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[



new Padding(
padding: new EdgeInsets.all(8.0),
child: new Text("${ticketGroups[i]['ticket_name']}",
style: const TextStyle(
fontSize: 15.0, fontFamily: 'Poppins')),
),
new Padding(
padding: new EdgeInsets.all(8.0),
child: new Text(ticketGroups[i]["used"].toString(),
style: const TextStyle(
fontSize: 15.0, fontFamily: 'Poppins')),
),

new Checkbox(
value: selected,
onChanged: (value) {
setState(() {
selected = !selected;
});

})

When I select one card, the following gets selected too

我希望只能勾选一张卡片,但是只要我勾选任何一张,所有卡片都会被勾选。卡片也是动态创建的,会不会是这个问题导致的?

最佳答案

正如 Günter 在他的评论中所说,您需要为每个卡片/列表项创建一个索引。到目前为止,我看到的最佳选择是将 ListView 与 itemBuilder 一起使用,如下所示:

return new ListView.builder(
itemBuilder: (context, index) => new Card(
shape: selected[index]
? new RoundedRectangleBorder(
side: new BorderSide(color: Colors.blue, width: 2.0),
borderRadius: BorderRadius.circular(4.0))
: new RoundedRectangleBorder(
side: new BorderSide(color: Colors.white, width: 2.0),
borderRadius: BorderRadius.circular(4.0)),
...
itemCount: selected.length, // Tell itemBuilder how many items the list has
... // Rest of your code...
);

关于dart - Flutter 复选框类 : When I tick a card, 所有其他的也都被选中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50800205/

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