[英]A dismissed Dismissible widget is still part of the tree. In flutter
[英]is it Possible to Implement a Dismissible widget for a button inside a SliverList in flutter
所以我要說我已經建立了一個看起來像這樣的條子清單。
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: () {}),
),
如何在一個圖標按鈕中實現可禁用的小部件,當按下顫動時,它會忽略列表中的項目?
好的,已經有一個包你做你需要的。
https://pub.dartlang.org/packages/flutter_slidable
可滑動列表項的Flutter實現,其中包含可以解除的方向滑動操作。
用法:
new Slidable(
delegate: new SlidableScrollDelegate(),
actionExtentRatio: 0.25,
child: new Container(
color: Colors.white,
child: new ListTile(
leading: new CircleAvatar(
backgroundColor: Colors.indigoAccent,
child: new Text('$3'),
foregroundColor: Colors.white,
),
title: new Text('Tile n°$3'),
subtitle: new Text('SlidableDrawerDelegate'),
),
),
actions: <Widget>[
new IconSlideAction(
caption: 'Archive',
color: Colors.blue,
icon: Icons.archive,
onTap: () => _showSnackBar('Archive'),
),
new IconSlideAction(
caption: 'Share',
color: Colors.indigo,
icon: Icons.share,
onTap: () => _showSnackBar('Share'),
),
],
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.