Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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?,

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading