Displaying the notification icon on the BottomNavigationBar icon

I want to display the notification icon (colored marble ) in the upper right cornerthe BottomNavigationBar Icon widget when a new message arrives on the Inbox tab. It is similar to https://developer.android.com/preview/features/notification-badges.html , but for my case it shows up in the app.

Any advice on overlaying an existing icon to create a custom icon class ?

+3


source to share


3 answers


Yes. This can be done by stacking two icons using widgets Stack

and Positioned

.



      new BottomNavigationBarItem(
        title: new Text('Home'),
        icon: new Stack(
          children: <Widget>[
            new Icon(Icons.home),
            new Positioned(  // draw a red marble
              top: 0.0,
              right: 0.0,
              child: new Icon(Icons.brightness_1, size: 8.0, 
                color: Colors.redAccent),
            )
          ]
        ),
      )

      

+7


source


I would use Stack

to render the marble on top Icon

by wrapping the marble in Positioned

, Align

or FractionallySizedBox

to position it however you want.



+2


source


You can also nest stacks. For example, if you want to add item_count to the shopping_cart icon, you can do this:

icon: new Stack(
              children: <Widget>[
                new Icon(Icons.shopping_cart),
                new Positioned(
                  top: 1.0,
                  right: 0.0,
                  child: new Stack(
                    children: <Widget>[
                      new Icon(Icons.brightness_1,
                          size: 18.0, color: Colors.green[800]),
                      new Positioned(
                        top: 1.0,
                        right: 4.0,
                        child: new Text(item_count,
                            style: new TextStyle(
                                color: Colors.white,
                                fontSize: 15.0,
                                fontWeight: FontWeight.w500)),
                      )
                    ],
                  ),
                )
              ],
            )

      

0


source







All Articles