我有数据列表,我想声明每个列表都有一个图标...每当用户单击该图标时..该图标将更改为另一个图标..这是代码
ListView.builder(
itemCount: data.length,
itemBuilder: (context, index) {
return Column(
children: <Widget>[
ListTile(
leading: InkWell(
onTap: () {
setState((){
match=true;
});
},
child:
match
? Icons.check
: Icons.error
),
title: Text(data[index],),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Text("subs here.."),
],
),
],
),
),
],
);
}),
从该代码中..用户单击第一个图标之后...列表视图构建器中的所有图标都已更改..是否可以仅更改我单击的图标(不是所有图标)的图标?
您可以维护为匹配变量所做的选定列表小部件的索引
setState((){
match=true;
_index = index;
});
然后添加一个条件
match && _index == index
? Icons.check
: Icons.error
),
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句