Title: is it Possible to Implement a Dismissible widget for a button inside a SliverList in flutter
Tags: android;dart;flutter
Question: so lets say I have built a sliverlist that looks like this.
return new Container(
child: new CustomScrollView(
scrollDirection: Axis.vertical,
shrinkWrap: false,
slivers: <Widget&gt;[
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),
),
),
],
));
and now i have a stateless widget called ModelCard to populate the list like this one
new Container(
padding: EdgeInsets.fromLTRB(80.0, 10.0, 0.0, 0.0),
child: new Text(
"${class.listDescription}",
style: new TextStyle(),
),
),
now I want to have an Icon button to dismiss an item so i added it inside the card
new Container(
padding: EdgeInsets.fromLTRB(350.0, 20.0, 0.0, 0.0),
child: new IconButton(
icon: new Icon(Icons.delete), onPressed: () {}),
),
How would you implement the dismissible widget inside an icon button that dismiss an Item in a list when pressed in flutter?
Comment: do you need to remove the item when you press the button?

Comment: could you describe the problem you have with your current implementation?

Comment: Oh yes I forgot to mention that, my bad

Comment: I can use the dismissible widget in the usual samples given in the documents and some samples in some sites, but I can't seem to find an example regarding using an button or icon button to dismiss an Item in a list view instead of using a the Dismissible where you just swipe it to remove it,

Here is the accepted answer: Ok , there is already a package which do what you need.
https://pub.dartlang.org/packages/flutter_slidable
A Flutter implementation of slidable list item with directional slide
actions that can be dismissed.
Usage:
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&gt;[
new IconSlideAction(
caption: 'Archive',
color: Colors.blue,
icon: Icons.archive,
onTap: () =&gt; _showSnackBar('Archive'),
),
new IconSlideAction(
caption: 'Share',
color: Colors.indigo,
icon: Icons.share,
onTap: () =&gt; _showSnackBar('Share'),
),
],
);
Comment for this answer: I think dissmisible doesn't have the option to select actions when you swipe the widget before it disappears.
Comment for this answer: Why not use Dismissible?


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 4, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2018:00:08/13/18', 'FavoriteCount': 1.0, 'PostTypeId': 1, 'Tags': '<android><dart><flutter>', 'Title': 'is it Possible to Implement a Dismissible widget for a button inside a SliverList in flutter', 'ViewCount': 3734, 'id': 51815074, 'user_AboutMe': '', 'user_AccountId': 13906007.0, 'user_DisplayName': 'user10040349', 'user_Reputation': 253.0, 'user_Views': 32.0, 'user_id': 10040349.0}}