1、pubspec.yaml添加
badges: ^3.1.1
2、flutter put get
3、传入index为显示badge的位置
BottomNavigationBarItem _buildTabs(int index) {
return BottomNavigationBarItem(
label: _tabs[index],
icon: badges.Badge(
badgeStyle: badges.BadgeStyle(
badgeColor: index == 1 ? Colors.red :Colors.transparent,
),
position: badges.BadgePosition.topEnd(top: -14),
badgeContent: index == 1 ? Text(
'$unreadCount',
style: const TextStyle(color: Colors.white,fontSize: 10),
):null,
child: Image.asset(
"images/${_tabIcons[index]}${index == _checkIndex ? "c" : "n"}.png",
width: 24,
height: 24,
),
),
);
}