aziza aziza - 8 days ago 4
Dart Question

How to use Dismissible on a Card object

If I have a Card object, how can I use the Dismissable widget on top of that so when the user swipe the card it executes an onDismissed function, I tried the following example but it asks for an identifier for the key:

Widget build(BuildContext context) {
return new Dismissible(
child: new Card(
//some code

),
key:/*how this works*/
);
}


is this doable by any mean ?

Answer

As stated in the docs a Dismissible needs a key to distinguish it from the other Dismissibles.

If the Dismissible is a list item, it must have a key that distinguishes it from the other items and its onDismissed callback must remove the item from the list.

For my first Todo-App I used ObjectKey for that purpose:

Widget build(BuildContext context) {
    return new Dismissible(
        child:  new Card(
            //some code
        ),
        key: new ObjectKey(widget.todo) 
    ); 
}

Does that help you? You should be able to use other Keys as long as they uniquely identify the Dismissible.