所有一级页面和不分二级页面

This commit is contained in:
2026-05-25 12:58:29 +08:00
parent b9f747de05
commit afef5c4ef1
158 changed files with 13082 additions and 1602 deletions

View File

@@ -1,51 +1,162 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:maibu_satabot_v2/features/main_container/presentation/bloc/tab_config_cubit.dart';
import 'package:cc_ui_kit/cc_ui_kit.dart';
import 'package:maibu_satabot_v2/features/main_container/presentation/cubit/tab_config_cubit.dart';
class CustomBottomNavBar extends StatelessWidget {
class CustomBottomNavBar extends StatefulWidget {
const CustomBottomNavBar({super.key});
@override
State<CustomBottomNavBar> createState() => _CustomBottomNavBarState();
}
class _CustomBottomNavBarState extends State<CustomBottomNavBar>
with TickerProviderStateMixin {
late AnimationController _animationController;
late Animation<double> _animation;
int _previousIndex = 0;
@override
void initState() {
super.initState();
_animationController = AnimationController(
duration: const Duration(milliseconds: 300),
vsync: this,
);
_animation = Tween<double>(
begin: 0.0,
end: 0.0,
).animate(
CurvedAnimation(
parent: _animationController,
curve: Curves.easeOutCubic,
),
);
}
@override
void dispose() {
_animationController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return BlocBuilder<TabConfigCubit, TabConfigState>(
builder: (context, state) {
if (state is! TabConfigLoaded) {
return const SizedBox.shrink();
}
final enabledTabs = state.config.enabledItems;
if (enabledTabs.isEmpty) {
return const SizedBox.shrink();
}
return Container(
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
blurRadius: 10,
offset: const Offset(0, -2),
),
],
return LayoutBuilder(
builder: (context, constraints) {
return _buildNavigationBar(
constraints: constraints,
enabledTabs: enabledTabs,
selectedIndex: state.selectedIndex,
);
},
);
},
);
}
Widget _buildNavigationBar({
required BoxConstraints constraints,
required List<dynamic> enabledTabs,
required int selectedIndex,
}) {
final tabWidth = constraints.maxWidth / enabledTabs.length;
final circleDiameter = 48.0;
// 当索引改变时,更新动画
WidgetsBinding.instance.addPostFrameCallback((_) {
if (_previousIndex != selectedIndex) {
final beginOffset = _previousIndex * tabWidth + tabWidth / 2;
final endOffset = selectedIndex * tabWidth + tabWidth / 2;
_animation = Tween<double>(
begin: beginOffset - circleDiameter / 2,
end: endOffset - circleDiameter / 2,
).animate(
CurvedAnimation(
parent: _animationController,
curve: Curves.easeOutCubic,
),
child: SafeArea(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
);
_previousIndex = selectedIndex;
_animationController.forward(from: 0.0);
}
});
return Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: const BorderRadius.vertical(top: Radius.circular(16)),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
blurRadius: 10,
offset: const Offset(0, -2),
),
],
),
child: SafeArea(
child: Stack(
alignment: Alignment.bottomCenter,
children: [
// 底层:Tab 列表
Row(
children: List.generate(enabledTabs.length, (index) {
final tab = enabledTabs[index];
final isSelected = index == state.selectedIndex;
return _buildNavItem(
context,
icon: _getIconData(tab.icon),
label: tab.name,
isSelected: isSelected,
onTap: () => context.read<TabConfigCubit>().selectTab(index),
final isSelected = index == selectedIndex;
return Expanded(
child: _buildNavItem(
context,
icon: _getIconData(tab.icon),
label: tab.name,
isSelected: isSelected,
onTap: () => context.read<TabConfigCubit>().selectTab(index),
),
);
}),
),
),
);
},
// 上层:动画圆形背景
AnimatedBuilder(
animation: _animation,
builder: (context, child) {
return Positioned(
bottom: 8,
left: _animation.value,
child: Container(
width: circleDiameter,
height: circleDiameter,
decoration: BoxDecoration(
color: const Color(0xFFF5F5F5),
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.12),
blurRadius: 8,
spreadRadius: 1,
offset: Offset.zero,
),
],
),
),
);
},
),
],
),
),
);
}
@@ -56,15 +167,18 @@ class CustomBottomNavBar extends StatelessWidget {
required bool isSelected,
required VoidCallback onTap,
}) {
return Expanded(
child: InkWell(
onTap: onTap,
return InkWell(
onTap: onTap,
child: Container(
height: 56,
alignment: Alignment.center,
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
icon,
color: isSelected ? const Color(0xFF2196F3) : Colors.grey,
color: isSelected ? Colors.black : const Color(0xFF666666),
size: 24,
),
const SizedBox(height: 4),
@@ -72,8 +186,8 @@ class CustomBottomNavBar extends StatelessWidget {
label,
style: TextStyle(
fontSize: 12,
color: isSelected ? const Color(0xFF2196F3) : Colors.grey,
fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal,
color: isSelected ? Colors.black : const Color(0xFF666666),
fontWeight: isSelected ? FontWeight.w500 : FontWeight.w400,
),
),
],
@@ -84,12 +198,18 @@ class CustomBottomNavBar extends StatelessWidget {
IconData _getIconData(String iconName) {
switch (iconName) {
case 'home_rounded':
return Icons.home_rounded;
case 'grid_view_rounded':
return Icons.grid_view_rounded;
case 'devices_rounded':
return Icons.devices_rounded;
case 'auto_awesome_rounded':
return Icons.auto_awesome_rounded;
case 'warning_amber_rounded':
return Icons.warning_amber_rounded;
case 'assignment_rounded':
return Icons.assignment_rounded;
case 'person_rounded':
return Icons.person_rounded;
default: