Browse Source

主页Tabbar的消息数量优化;

master
ZHR007 2 months ago
parent
commit
728883ef01
1 changed files with 12 additions and 59 deletions
  1. 71
      lib/pages/main/main_page.dart

71
lib/pages/main/main_page.dart

@ -108,76 +108,29 @@ class _MainPageState extends State<MainPage> {
componentType: TDBottomTabBarComponentType.normal,
useVerticalDivider: false,
navigationTabs: [
tabItem('首页', Assets.imagesHomePre, Assets.imagesHomeNol, 0),
tabItem('找对象', Assets.imagesDiscoverPre, Assets.imagesDiscoverNol, 1),
tabItemWithBadge('消息', Assets.imagesMessagePre, Assets.imagesMessageNol, 2, unreadCount),
tabItem('我的', Assets.imagesMinePre, Assets.imagesMineNol, 3),
tabItem('首页', Assets.imagesHomePre, Assets.imagesHomeNol, 0, 0),
tabItem('找对象', Assets.imagesDiscoverPre, Assets.imagesDiscoverNol, 1, 0),
tabItem('消息', Assets.imagesMessagePre, Assets.imagesMessageNol, 2, unreadCount),
tabItem('我的', Assets.imagesMinePre, Assets.imagesMineNol, 3, 0),
]
);
);
});
}
/// item
TDBottomTabBarTabConfig tabItem(String title, String selectedIcon, String unselectedIcon, int index) {
TDBottomTabBarTabConfig tabItem(String title, String selectedIcon, String unselectedIcon, int index, int unreadCount) {
return TDBottomTabBarTabConfig(
tabText: title,
selectedIcon: Image.asset(selectedIcon, width: 25, height: 25, fit: BoxFit.cover),
unselectedIcon: Image.asset(unselectedIcon, width: 25, height: 25, fit: BoxFit.cover),
selectTabTextStyle: TextStyle(color: Color(0xFFED4AC3)),
unselectTabTextStyle: TextStyle(color: Color(0xFF999999)),
onTap: () {
currentIndex = index;
pageController.jumpToPage(index);
},
);
}
/// item
TDBottomTabBarTabConfig tabItemWithBadge(String title, String selectedIcon, String unselectedIcon, int index, int unreadCount) {
//
Widget buildIconWithBadge(String iconPath, bool isSelected) {
return Stack(
clipBehavior: Clip.none,
children: [
Image.asset(iconPath, width: 25, height: 25, fit: BoxFit.cover),
if (unreadCount > 0)
Positioned(
right: -6.w,
top: -6.w,
child: Container(
padding: EdgeInsets.symmetric(horizontal: unreadCount > 99 ? 4.w : 5.w, vertical: 2.w),
decoration: BoxDecoration(
color: Color(0xFFFF3B30),
borderRadius: BorderRadius.circular(10.w),
border: Border.all(color: Colors.white, width: 1.w),
),
constraints: BoxConstraints(
minWidth: 16.w,
minHeight: 16.w,
),
child: Center(
child: Text(
unreadCount > 99 ? '99+' : unreadCount.toString(),
style: TextStyle(
color: Colors.white,
fontSize: 10.sp,
fontWeight: FontWeight.w500,
),
textAlign: TextAlign.center,
),
),
),
),
],
);
}
return TDBottomTabBarTabConfig(
tabText: title,
selectedIcon: buildIconWithBadge(selectedIcon, true),
unselectedIcon: buildIconWithBadge(unselectedIcon, false),
selectTabTextStyle: TextStyle(color: Color(0xFFED4AC3)),
unselectTabTextStyle: TextStyle(color: Color(0xFF999999)),
badgeConfig: BadgeConfig(
showBadge: unreadCount > 0,
tdBadge: TDBadge(TDBadgeType.message, count: unreadCount.toString(), maxCount: '99'),
badgeTopOffset: -2,
badgeRightOffset: unreadCount >= 99 ? -20 : (unreadCount >= 10 ? -15 : -10),
),
onTap: () {
currentIndex = index;
pageController.jumpToPage(index);

Loading…
Cancel
Save