bottom_navigation_bar.dart 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import 'dart:ui';
  2. import 'package:flutter/material.dart';
  3. import 'package:get/get.dart';
  4. import '../../../../config/translations/strings_enum.dart';
  5. import '../../../../config/theme/light_theme_colors.dart';
  6. import '../../../../config/theme/dark_theme_colors.dart';
  7. import '../../../data/sp/ix_sp.dart';
  8. class IXBottomNavigationBar extends StatelessWidget {
  9. final int currentIndex;
  10. final int lastIndex;
  11. final Function(int) onTap;
  12. const IXBottomNavigationBar({
  13. super.key,
  14. required this.currentIndex,
  15. required this.lastIndex,
  16. required this.onTap,
  17. });
  18. @override
  19. Widget build(BuildContext context) {
  20. return ClipRRect(
  21. child: BackdropFilter(
  22. filter: ImageFilter.blur(sigmaX: 4, sigmaY: 10),
  23. child: SafeArea(
  24. child: Row(
  25. mainAxisAlignment: MainAxisAlignment.spaceAround,
  26. children: [
  27. _buildNavItem(
  28. icon: Icons.gamepad,
  29. label: Strings.bottomBarGames.tr,
  30. index: 0,
  31. onTap: () => onTap(0),
  32. ),
  33. _buildNavItem(
  34. icon: Icons.bolt,
  35. label: Strings.bottomBarBoost.tr,
  36. index: 1,
  37. onTap: () => onTap(1),
  38. ),
  39. _buildNavItem(
  40. icon: Icons.person,
  41. label: Strings.bottomBarMe.tr,
  42. index: 2,
  43. onTap: () => onTap(2),
  44. ),
  45. ],
  46. ),
  47. ),
  48. ),
  49. );
  50. }
  51. Widget _buildNavItem({
  52. required IconData icon,
  53. required String label,
  54. required int index,
  55. required VoidCallback onTap,
  56. }) {
  57. final isSelected = currentIndex == index;
  58. final bool isLightTheme = IXSP.getThemeIsLight();
  59. // 根据主题获取颜色
  60. final selectedColor = isLightTheme
  61. ? LightThemeColors.bottomBarSelectedColor
  62. : DarkThemeColors.bottomBarSelectedColor;
  63. final unselectedColor = isLightTheme
  64. ? LightThemeColors.bottomBarUnselectedColor
  65. : DarkThemeColors.bottomBarUnselectedColor;
  66. return GestureDetector(
  67. onTap: onTap,
  68. behavior: HitTestBehavior.opaque,
  69. child: Stack(
  70. children: [
  71. Container(
  72. width: 100,
  73. height: 52,
  74. margin: const EdgeInsets.only(top: 12),
  75. child: Column(
  76. mainAxisAlignment: MainAxisAlignment.center,
  77. crossAxisAlignment: CrossAxisAlignment.center,
  78. children: [
  79. AnimatedSwitcher(
  80. duration: const Duration(milliseconds: 300),
  81. transitionBuilder: (child, animation) {
  82. return FadeTransition(opacity: animation, child: child);
  83. },
  84. child: Icon(
  85. icon,
  86. key: ValueKey("bottom_bar_icon_$isSelected"),
  87. size: 24,
  88. color: isSelected ? selectedColor : unselectedColor,
  89. ),
  90. ),
  91. AnimatedDefaultTextStyle(
  92. duration: const Duration(milliseconds: 300),
  93. curve: Curves.easeInOut,
  94. style: TextStyle(
  95. fontSize: 12,
  96. height: 1.4,
  97. color: isSelected ? selectedColor : unselectedColor,
  98. fontWeight: FontWeight.w500,
  99. ),
  100. child: Text(label),
  101. ),
  102. ],
  103. ),
  104. ),
  105. ],
  106. ),
  107. );
  108. }
  109. }