【发布时间】:2020-07-22 15:44:46
【问题描述】:
我在 ListView 中有 ListTile,RaisedButton 作为尾随,我想在点击 btn 时更改颜色和图标,问题是如果我在 setstate 方法上更改它,所有 listTile 按钮都会更改。那么如何确定每一个呢?
Widget _getList(BuildContext context,int index,) {
return Card(
elevation: 3,
child: Column(
children: <Widget>[
ListTile(
leading: Image.asset(
"assets/" + _allDevices[index].image,
fit: BoxFit.cover,
),
title: Text(_allDevices[index].name),
subtitle: Text(_allDevices[index].desc),
trailing: SizedBox.fromSize(
size: Size(56, 56), // button width and height
child: ClipOval(
child: RaisedButton(
elevation: 2,
splashColor: Colors.red,
color: Colors.blue,
onPressed: () {
setState(() {
//pro should do something here... switch index or something....
});
},
child: Icon(Icons.lock_open),
),
)),
onTap: () {},
)
],
),
);
}
【问题讨论】: