我正在与Flutter合作,正在努力从树中删除“不合格”对象.下面是我的代码.我创建了一个自定义类,该类存储在列表“ newlist”中.我似乎从List和setState()中删除了dismissible对象,但是它似乎不起作用.任何帮助是极大的赞赏.
return new dismissible(key: new Key("newlist"),
direction: dismissDirection.horizontal,
ondismissed: (dismissDirection direction) {
setState(() {
newlist.remove(newlist[index]);
print(newlist.length);
});
},
child: new ListTile(
leading: const
Icon(Icons.album),
title: new Text(newlist[index].amount),
subtitle: new Text(
newlist[index].name)));
})),
解决方法:
我已经解决了使用项目名称列表长度作为关键.因为可能会有一些具有相同价值的物品
return dismissible(
key: Key(item.name + _paths.length.toString()),
ondismissed: (direction) {
setState(() {
_paths.removeAt(index);
});
// Show a red background as the item is swiped away
background: Container(color: Colors.red),
child: Container(child: new Texts().tallText(item.name)),
);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。