|
|
|
@ -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); |
|
|
|
|