Android 是否可以在flift中为SliverList中的按钮实现一个可拒绝的小部件
假设我建立了一个类似这样的sliverlistAndroid 是否可以在flift中为SliverList中的按钮实现一个可拒绝的小部件,android,dart,flutter,Android,Dart,Flutter,假设我建立了一个类似这样的sliverlist return new Container( child: new CustomScrollView( scrollDirection: Axis.vertical, shrinkWrap: false, slivers: <Widget>[ new SliverPadding(
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),
),
),
],
));
现在我想有一个图标按钮来关闭一个项目,所以我把它添加到卡里面
new Container(
padding: EdgeInsets.fromLTRB(350.0, 20.0, 0.0, 0.0),
child: new IconButton(
icon: new Icon(Icons.delete), onPressed: () {}),
),
您将如何在图标按钮中实现dismissible小部件,当在Flatter中按下该按钮时,该按钮将关闭列表中的项目?好的,已经有一个包可以满足您的需要 具有方向滑动的可滑动列表项的颤振实现 可以驳回的行动 用法:
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'),
),
],
);
newslideable(
委托:新的SlideableScrollDelegate(),
行动延伸率:0.25,
子容器:新容器(
颜色:颜色,白色,
孩子:新的ListTile(
领先:新CircleAvatar(
背景颜色:Colors.indigoAccent,
子项:新文本(“$3”),
前底色:颜色。白色,
),
标题:新文本('Tile n°$3'),
副标题:新文本(“SlideableDrawerDelegate”),
),
),
行动:[
新IconSlideAction(
标题:"档案",,
颜色:颜色,蓝色,
图标:Icons.archive,
onTap:()=>\u showSnackBar('Archive'),
),
新IconSlideAction(
描述:“共享”,
颜色:颜色,靛蓝,
图标:Icons.share,
onTap:()=>\u showSnackBar('Share'),
),
],
);
您按下按钮时是否需要删除该项?哦,是的,我忘了提及,我的朋友。您能描述一下您当前实现中存在的问题吗?我可以在文档中给出的常见示例和某些站点中的一些示例中使用dismissible widget,但我似乎找不到在列表视图中使用按钮或图标按钮来关闭项目而不是使用Dismissible的例子,如果您只是滑动它来删除它,为什么不使用Dismissible?我认为Dismissible没有选择在小部件消失之前滑动它时的操作。
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'),
),
],
);