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

How to stack two icons one on top of the other?

I have two icons in a stack. I want one to hide the other, but instead it’s semi-transparent and the other is shown behind it.

This is the code:

Stack(
     children: [
         Container(child: Icon(Icons.account_circle_rounded), padding: EdgeInsets.only(left: 10),),
         Container(child: Icon(Icons.account_circle_rounded), padding: EdgeInsets.only(left: 20),),
    ],
)

This is how it looks:
enter image description here

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

>Solution :

Icons are more like SVG, use vector to draw shape. There are some empty spaces inside the icon to draw the path, and we can see the background though this. Also, it contains padding around it, You can use your assets to draw the UI.

We can wrap with another ColoredBox to hide the background icon, but it will get extra padding from IconData.

This snippet shows basic level structure.

SizedBox(
  height: 24,
  width: 24 * 1.7,
  child: Stack(
    alignment: Alignment.center,
    children: [
      Align(
        alignment: Alignment.centerLeft,
        child: Container(
          child: const Icon(
            Icons.account_circle_rounded,
          ),
          decoration: const BoxDecoration(
            color: Colors.white,
            shape: BoxShape.circle,
          ),
        ),
      ),
      Align(
        alignment: Alignment.centerRight,
        child: Container(
          child: const Icon(
            Icons.account_circle_sharp,
          ),
          decoration: const BoxDecoration(
            color: Colors.white,
            shape: BoxShape.circle,
          ),
        ),
      ),
    ],
  ),
),

Widget renders bottom to top.

enter image description here

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