我想更改选定项目(_ itemSelected)的视图。当我选择一个项目但其他项目没有刷新时,它可以工作。是否有类似notifydatasetchanged的东西?我错过了什么?谢谢!
class MyItemListItem extends State<MyItemList> {
final MyItem item;
MyItemListItem(this.item);
@override
Widget build(BuildContext context) {
return new ListTile(
key: _itemListItem,
onTap: () {
_scaffoldKey.currentState.showSnackBar(new SnackBar(
content: new Text("You clicked item number " + item.name)));
_itemSelected = item;
setState(() {
});
},
leading: new CircleAvatar(backgroundColor: Colors.blue),
title: _itemSelected != null && item == _itemSelected
? new Row(children: <Widget>[new Text("Foo"), new Text("Bar")])
: new Row(
children: <Widget>[
new Expanded(child: new Text(item.name)),
],
));
}
}
答案 0 :(得分:0)
好的,我发现了问题所在。 就像GünterZöchbauer建议我添加的
_scaffoldKey.currentState.showSnackBar(new SnackBar(
content: new Text("You clicked item number " + item.name)));
_itemSelected = item;
home.addItem();
},
其中home是父窗口小部件。
void addItem() {
setState(() {
});
}