【发布时间】:2018-08-13 04:07:42
【问题描述】:
假设我已经建立了一个看起来像这样的 sliverlist。
return new Container(
child: new CustomScrollView(
scrollDirection: Axis.vertical,
shrinkWrap: false,
slivers: <Widget>[
new SliverPadding(
padding: const EdgeInsets.symmetric(vertical: 2.0),
sliver: new SliverList(
delegate: new SliverChildBuilderDelegate(
(BuildContext context, int index) {
ModelClass class= _List[index];
return new Dismissible(
key: new ObjectKey(_List[index]),
child: ModelCard(class),
onDismissed: (DismissDirection direction) {
setState(() {
_List.removeAt(index);
direction == DismissDirection.endToStart;
});
},
background: new Container(
color: const Color.fromRGBO(183, 28, 28, 0.8),
child: new Center(
child: new Text(
"Item Removed",
style: new TextStyle(color: Colors.white),
),
)),
);
// return new ModelCard(class);
}, childCount: _List.length),
),
),
],
));
现在我有一个名为 ModelCard 的无状态小部件来填充这样的列表
new Container(
padding: EdgeInsets.fromLTRB(80.0, 10.0, 0.0, 0.0),
child: new Text(
"${class.listDescription}",
style: new TextStyle(),
),
),
现在我想要一个图标按钮来关闭一个项目,所以我将它添加到卡片中
new Container(
padding: EdgeInsets.fromLTRB(350.0, 20.0, 0.0, 0.0),
child: new IconButton(
icon: new Icon(Icons.delete), onPressed: () {}),
),
您将如何在图标按钮内实现可关闭小部件,当在颤动中按下时,该小部件会关闭列表中的项目?
【问题讨论】:
-
按下按钮时是否需要移除项目?
-
哦,是的,我忘了说,我的错
-
您能描述一下您当前的实现遇到的问题吗?
-
我可以在文档中给出的常用示例和某些站点中的一些示例中使用可关闭小部件,但我似乎找不到有关使用按钮或图标按钮关闭项目的示例在列表视图中,而不是使用 Dismissible,您只需滑动即可将其删除,