关怀模式
This commit is contained in:
@@ -1,15 +1,18 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import '../constants/app_constants.dart';
|
||||
import '../views/home/home_page.dart';
|
||||
import '../views/discover_page.dart';
|
||||
import '../views/favorites_page.dart';
|
||||
import '../views/profile/profile_page.dart';
|
||||
import '../views/profile/level/poetry.dart';
|
||||
import '../views/home/care/care_poetry_page.dart';
|
||||
import '../services/get/main_navigation_controller.dart';
|
||||
import '../services/get/profile_controller.dart';
|
||||
import '../services/get/theme_controller.dart';
|
||||
import '../services/get/tap_liquid_glass_controller.dart';
|
||||
import '../services/get/care_controller.dart';
|
||||
import 'tap-liquid-glass.dart';
|
||||
import 'care/care_mode_navigation.dart';
|
||||
|
||||
/// 时间: 2025-03-21
|
||||
/// 功能: 主导航页面,包含底部导航栏和4个主要页面
|
||||
@@ -24,9 +27,11 @@ class MainNavigation extends StatelessWidget {
|
||||
// 初始化导航控制器(只初始化一次)
|
||||
Get.lazyPut(() => MainNavigationController());
|
||||
Get.lazyPut(() => TapLiquidGlassController());
|
||||
Get.lazyPut(() => CareController());
|
||||
final controller = Get.find<MainNavigationController>();
|
||||
final themeController = Get.find<ThemeController>();
|
||||
final glassController = Get.find<TapLiquidGlassController>();
|
||||
final careController = Get.find<CareController>();
|
||||
|
||||
final List<Widget> pages = [
|
||||
HomePage(),
|
||||
@@ -35,25 +40,27 @@ class MainNavigation extends StatelessWidget {
|
||||
const ProfilePage(),
|
||||
];
|
||||
|
||||
final primaryColor = themeController.currentThemeColor;
|
||||
|
||||
final List<BottomNavigationBarItem> bottomNavItems = [
|
||||
const BottomNavigationBarItem(
|
||||
icon: Icon(Icons.home),
|
||||
activeIcon: Icon(Icons.home, color: AppConstants.primaryColor),
|
||||
BottomNavigationBarItem(
|
||||
icon: const Icon(Icons.home),
|
||||
activeIcon: Icon(Icons.home, color: primaryColor),
|
||||
label: '主页',
|
||||
),
|
||||
const BottomNavigationBarItem(
|
||||
icon: Icon(Icons.explore),
|
||||
activeIcon: Icon(Icons.explore, color: AppConstants.primaryColor),
|
||||
BottomNavigationBarItem(
|
||||
icon: const Icon(Icons.explore),
|
||||
activeIcon: Icon(Icons.explore, color: primaryColor),
|
||||
label: '发现',
|
||||
),
|
||||
const BottomNavigationBarItem(
|
||||
icon: Icon(Icons.favorite_border),
|
||||
activeIcon: Icon(Icons.favorite, color: AppConstants.primaryColor),
|
||||
BottomNavigationBarItem(
|
||||
icon: const Icon(Icons.favorite_border),
|
||||
activeIcon: Icon(Icons.favorite, color: primaryColor),
|
||||
label: '收藏',
|
||||
),
|
||||
const BottomNavigationBarItem(
|
||||
icon: Icon(Icons.person_outline),
|
||||
activeIcon: Icon(Icons.person, color: AppConstants.primaryColor),
|
||||
BottomNavigationBarItem(
|
||||
icon: const Icon(Icons.person_outline),
|
||||
activeIcon: Icon(Icons.person, color: primaryColor),
|
||||
label: '个人',
|
||||
),
|
||||
];
|
||||
@@ -61,11 +68,23 @@ class MainNavigation extends StatelessWidget {
|
||||
return Obx(() {
|
||||
final isDark = themeController.isDarkMode;
|
||||
final useGlass = glassController.isEnabled;
|
||||
final isCareMode = careController.isCareModeEnabled;
|
||||
|
||||
// 关怀模式开启时,使用关怀模式的导航栏
|
||||
if (isCareMode) {
|
||||
return Scaffold(body: _buildCareModeBody(careController));
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
body: useGlass
|
||||
? _buildGlassBody(controller, pages)
|
||||
: _buildClassicBody(controller, pages, isDark, bottomNavItems),
|
||||
: _buildClassicBody(
|
||||
controller,
|
||||
pages,
|
||||
isDark,
|
||||
bottomNavItems,
|
||||
primaryColor,
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -79,10 +98,7 @@ class MainNavigation extends StatelessWidget {
|
||||
return Stack(
|
||||
children: [
|
||||
// 页面内容 - 延伸到屏幕底部
|
||||
IndexedStack(
|
||||
index: controller.currentIndex.value,
|
||||
children: pages,
|
||||
),
|
||||
IndexedStack(index: controller.currentIndex.value, children: pages),
|
||||
// 悬浮的液态玻璃导航栏
|
||||
Positioned(
|
||||
left: 0,
|
||||
@@ -109,6 +125,7 @@ class MainNavigation extends StatelessWidget {
|
||||
List<Widget> pages,
|
||||
bool isDark,
|
||||
List<BottomNavigationBarItem> items,
|
||||
Color primaryColor,
|
||||
) {
|
||||
return Column(
|
||||
children: [
|
||||
@@ -143,7 +160,7 @@ class MainNavigation extends StatelessWidget {
|
||||
}
|
||||
},
|
||||
type: BottomNavigationBarType.fixed,
|
||||
selectedItemColor: AppConstants.primaryColor,
|
||||
selectedItemColor: primaryColor,
|
||||
unselectedItemColor: isDark ? Colors.grey[400] : Colors.grey[600],
|
||||
backgroundColor: isDark ? const Color(0xFF2A2A2A) : Colors.white,
|
||||
elevation: 0,
|
||||
@@ -156,4 +173,34 @@ class MainNavigation extends StatelessWidget {
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建关怀模式主体
|
||||
/// 使用 Stack 布局,让导航栏悬浮在页面内容上方
|
||||
Widget _buildCareModeBody(CareController careController) {
|
||||
return Obx(() {
|
||||
final carePages = [const CarePoetryPage(), const PoetryLevelPage()];
|
||||
|
||||
return Stack(
|
||||
children: [
|
||||
// 页面内容 - 延伸到屏幕底部
|
||||
IndexedStack(
|
||||
index: careController.careNavigationIndex,
|
||||
children: carePages,
|
||||
),
|
||||
// 悬浮的关怀模式导航栏
|
||||
Positioned(
|
||||
left: 0,
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
child: CareModeNavigation(
|
||||
currentIndex: careController.careNavigationIndex,
|
||||
onTap: (index) {
|
||||
careController.switchCareNavigation(index);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user