Flutter – Slidable, cannot put svg for icon property of Slidable

Advertisements
Slidable(
      groupTag: 0,
      key: UniqueKey(),
      endActionPane: ActionPane(
        children: [
          SlidableAction(
            onPressed: (BuildContext context) {
                //whatever I will do here
            },
            icon: Icons.delete
          )// SvgPicture.asset(Assets.svg.trash.svg()),)
        ],
      ),
      child: _makeColumnTile(
        myCard,
      ),

    );

This is just a basic slidable item, which I am doing for every list item I have. I understand, and can work with slidable and listTile. However, I want to put my own custom svg file I saved in my assets folder, not pre-built Icons. But the icon: is apparently only wanting IconData

I tried putting svg directly with SvgPicture.asset(Assets.svg.trash.svg()), but the error is

The argument type SvgPicture can’t be assigned to the parameter type IconData?,

also when I want to assign Icon to icon, this error pops up.

The argument type ‘Icon’ can’t be assigned to the parameter type ‘IconData?.

I understand why I cannot assign those properties, but isn’t there any way I could solve this problem?

>Solution :

The SlidableAction only accepts IconData in its icon property. A list of MaterialIcons is available here.

SlidableAction(
   icon: Icons.archive,
 ),

For your use case, you can instead use a CustomSlidableAction (check the package’s API reference here).

CustomSlidableAction (
  child: //Your action's icon or label.
 )

You can pass your SVG as a child to it.

Leave a ReplyCancel reply