当有新消息时,我想在 BottomNavigationBar 的 Icon 小部件的 右上角 显示通知徽章(彩色 大理石)已到达收件箱选项卡。类似于 https://developer.android.com/preview/features/notification-badges.html但就我而言,它显示在应用内。
在现有图标上绘制叠加层以创建自定义图标类的任何提示?
最佳答案
计数徽章的另一种变体(使用 Stack of Icon 实现并包裹在容器文本中,当计数器增加时会拉伸(stretch)):
BottomNavigationBarItem(
icon: new Stack(
children: <Widget>[
new Icon(Icons.notifications),
new Positioned(
right: 0,
child: new Container(
padding: EdgeInsets.all(1),
decoration: new BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(6),
),
constraints: BoxConstraints(
minWidth: 12,
minHeight: 12,
),
child: new Text(
'$_counter',
style: new TextStyle(
color: Colors.white,
fontSize: 8,
),
textAlign: TextAlign.center,
),
),
)
],
),
title: Text('Notifications'),
),
https://stackoverflow.com/questions/45155104/