-暂提交-bug未处理
This commit is contained in:
@@ -1,84 +1,163 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:google_nav_bar/google_nav_bar.dart';
|
||||
import 'package:maibu_satabot_v2/features/main_container/presentation/cubit/tab_config_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/features/main_container/domain/tab_config.dart';
|
||||
import 'package:maibu_satabot_v2/features/home/presentation/pages/home_page.dart';
|
||||
import 'package:maibu_satabot_v2/features/ai/presentation/pages/ai_page.dart';
|
||||
import 'package:maibu_satabot_v2/features/waring_center/presentation/pages/warning_center_page.dart';
|
||||
import 'package:maibu_satabot_v2/features/my/presentation/pages/my_page.dart';
|
||||
|
||||
class MainWrapper extends StatelessWidget {
|
||||
final StatefulNavigationShell navigationShell;
|
||||
class MainWrapper extends StatefulWidget {
|
||||
const MainWrapper({super.key});
|
||||
|
||||
const MainWrapper({super.key, required this.navigationShell});
|
||||
@override
|
||||
State<MainWrapper> createState() => _MainWrapperState();
|
||||
}
|
||||
|
||||
class _MainWrapperState extends State<MainWrapper> {
|
||||
int _currentIndex = 0;
|
||||
final PageController _pageController = PageController();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_pageController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
IconData _getIconData(String iconName) {
|
||||
switch (iconName) {
|
||||
case 'grid_view_rounded':
|
||||
return Icons.grid_view_rounded;
|
||||
case 'auto_awesome_rounded':
|
||||
return Icons.auto_awesome_rounded;
|
||||
case 'warning_amber_rounded':
|
||||
return Icons.warning_amber_rounded;
|
||||
case 'person_rounded':
|
||||
return Icons.person_rounded;
|
||||
default:
|
||||
return Icons.home_rounded;
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildCurrentPage(TabConfigItem tab) {
|
||||
switch (tab.id) {
|
||||
case 'home':
|
||||
return const HomePage();
|
||||
case 'ai':
|
||||
return const AiPage();
|
||||
case 'warning':
|
||||
return const WarningCenterPage();
|
||||
case 'my':
|
||||
return const MyPage();
|
||||
default:
|
||||
return const HomePage();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
extendBody: true, // 必须开启,让内容流过导航栏下方
|
||||
body: navigationShell,
|
||||
bottomNavigationBar: Container(
|
||||
margin: const EdgeInsets.fromLTRB(20, 0, 20, 10),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(32),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.12), // 强化阴影,增加悬浮感
|
||||
blurRadius: 30,
|
||||
offset: const Offset(0, 10),
|
||||
return BlocBuilder<TabConfigCubit, TabConfigState>(
|
||||
builder: (context, state) {
|
||||
if (state is! TabConfigLoaded) {
|
||||
return const Scaffold(body: Center(child: CircularProgressIndicator()));
|
||||
}
|
||||
|
||||
final config = state.config;
|
||||
final enabledItems = config.enabledItems;
|
||||
|
||||
if (enabledItems.isEmpty) {
|
||||
return const Scaffold(
|
||||
body: Center(
|
||||
child: Text('请至少启用一个 Tab'),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(32),
|
||||
child: BackdropFilter(
|
||||
filter: ImageFilter.blur(sigmaX: 16, sigmaY: 16), // 增加模糊半径
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
// 降低白色透明度到 0.4,减少“灰蒙蒙”的白雾感,让背景颜色更亮地透出来
|
||||
color: Colors.white.withOpacity(0.4),
|
||||
borderRadius: BorderRadius.circular(32),
|
||||
border: Border.all(
|
||||
// 使用极细的深色半透明边框勾勒轮廓
|
||||
color: Colors.black.withOpacity(0.08),
|
||||
width: 0.5,
|
||||
);
|
||||
}
|
||||
|
||||
if (_currentIndex >= enabledItems.length) {
|
||||
_currentIndex = 0;
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
extendBody: true,
|
||||
body: PageView(
|
||||
controller: _pageController,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
onPageChanged: (index) {
|
||||
setState(() {
|
||||
_currentIndex = index;
|
||||
});
|
||||
},
|
||||
children: enabledItems.map((tab) => _buildCurrentPage(tab)).toList(),
|
||||
),
|
||||
bottomNavigationBar: Container(
|
||||
margin: const EdgeInsets.fromLTRB(20, 0, 20, 10),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(32),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.12),
|
||||
blurRadius: 30,
|
||||
offset: const Offset(0, 10),
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
top: false,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 10,
|
||||
vertical: 8,
|
||||
),
|
||||
child: GNav(
|
||||
rippleColor: Colors.transparent,
|
||||
hoverColor: Colors.transparent,
|
||||
gap: 10,
|
||||
// 【关键修改】选中状态:纯黑背景 + 纯白图标/文字
|
||||
activeColor: Colors.white,
|
||||
tabBackgroundColor: Colors.black,
|
||||
// 未选中状态:深黑色
|
||||
color: Colors.black87,
|
||||
iconSize: 24,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 18,
|
||||
vertical: 10,
|
||||
],
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(32),
|
||||
child: BackdropFilter(
|
||||
filter: ImageFilter.blur(sigmaX: 16, sigmaY: 16),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.4),
|
||||
borderRadius: BorderRadius.circular(32),
|
||||
border: Border.all(
|
||||
color: Colors.black.withOpacity(0.08),
|
||||
width: 0.5,
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
top: false,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 10,
|
||||
vertical: 8,
|
||||
),
|
||||
child: GNav(
|
||||
rippleColor: Colors.transparent,
|
||||
hoverColor: Colors.transparent,
|
||||
gap: 10,
|
||||
activeColor: Colors.white,
|
||||
tabBackgroundColor: Colors.black,
|
||||
color: Colors.black87,
|
||||
iconSize: 24,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 18,
|
||||
vertical: 10,
|
||||
),
|
||||
duration: const Duration(milliseconds: 300),
|
||||
selectedIndex: _currentIndex,
|
||||
onTabChange: (index) {
|
||||
setState(() {
|
||||
_currentIndex = index;
|
||||
});
|
||||
_pageController.jumpToPage(index);
|
||||
},
|
||||
tabs: enabledItems.map((item) {
|
||||
return GButton(
|
||||
icon: _getIconData(item.icon),
|
||||
text: item.name,
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
duration: const Duration(milliseconds: 300),
|
||||
selectedIndex: navigationShell.currentIndex,
|
||||
onTabChange: (index) {
|
||||
navigationShell.goBranch(index);
|
||||
},
|
||||
tabs: const [
|
||||
GButton(icon: Icons.grid_view_rounded, text: '状态'),
|
||||
GButton(icon: Icons.auto_awesome_rounded, text: 'AI'),
|
||||
GButton(icon: Icons.person_rounded, text: '我的'),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user