Home > Software engineering >  how to change the icon when have no children in flutter widget?
how to change the icon when have no children in flutter widget?

Time:08-04

Notification Case Senerio

IconButton(
            onPressed: () {
              Navigator.pushNamed(context, Routes.notification);
            },
            icon: ImageIcon(
              Notification == null ? AssetImage("../../images/Icons/bell.png")  : AssetImage("../../images/Icons/bin.png"),
              size: 21,
            ),
          ),

What i wanted is to change the icon whenever any specific widget contains 0 children

My Idea is to change the notification icon when we have zero notification and use another icon when notification widget have same children or have some notification

CodePudding user response:

Check out this flutter package

result

now just add items to your List in StatefulWidget by setState and do what you like, if you need IconButton just pass it in child of your Badge,

read badges doc to fix badgeContent, good luck

  • Related