У меня есть один просмотр списка в моем приложении.В каждом ряду есть несколько кнопок, которые влияют только на этот ряд.Я не хочу обновлять весь Listview
.Когда я вызываю setState()
при нажатии кнопок, это приводит к обновлению всего Listview
.
Как выполнить обновление только в одном и том же ряду кнопок внутри ряда?
В моемнажатие кода на кнопку должно вызвать изменение цвета той же кнопки:
....
....
....
List<mPlay> playList = new List();
....
....
....
@override
Widget build(BuildContext context) {
return new Directionality(
textDirection: globals.textDirection,
child: new Scaffold(
key: globalKey,
body: (playList != null && playList.length > 0)
? new SmartRefresher(
headerBuilder: _buildHeader,
enablePullDown: true,
enablePullUp: true,
onRefresh: _onRefresh,
onOffsetChange: _onOffsetCallback,
child: new ListView.builder(
padding: const EdgeInsets.all(0),
itemCount: playList.length,
itemBuilder: (context, i) {
return _buildRow(playList[i], i);
},
))
: EmptyWidget()));
}
Widget _buildRow(mPlay play, int index) {
return new Card(
child: new Container(
child: new Row(children: <Widget>[
new InkWell(
child: new IconButton(
icon: Icon(
Icons.group_add,
color: play.isContributed == "1"
? Colors.blueAccent
: Colors.black,
),
onPressed: () {
play.isContributed =
play.isContributed == "0" ? "1" : "0";
setState(() {
playList[index].isContributed =
play.isContributed;
});
}))
])
))
}