所有一级页面和不分二级页面
This commit is contained in:
@@ -1,51 +0,0 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:maibu_satabot_v2/features/main_container/domain/tab_config.dart';
|
||||
|
||||
class TabConfigState {
|
||||
final TabConfig config;
|
||||
final int selectedIndex;
|
||||
|
||||
const TabConfigState({
|
||||
required this.config,
|
||||
this.selectedIndex = 0,
|
||||
});
|
||||
|
||||
TabConfigState copyWith({
|
||||
TabConfig? config,
|
||||
int? selectedIndex,
|
||||
}) {
|
||||
return TabConfigState(
|
||||
config: config ?? this.config,
|
||||
selectedIndex: selectedIndex ?? this.selectedIndex,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class TabConfigCubit extends Cubit<TabConfigState> {
|
||||
TabConfigCubit() : super(TabConfigState(config: TabConfig.defaultConfig()));
|
||||
|
||||
/// 切换 Tab 的启用状态
|
||||
void toggleTab(String tabId) {
|
||||
final newConfig = state.config.toggleItem(tabId);
|
||||
|
||||
// 如果当前选中的 Tab 被禁用,自动切换到第一个启用的 Tab
|
||||
int newIndex = state.selectedIndex;
|
||||
if (newIndex >= newConfig.enabledItems.length) {
|
||||
newIndex = 0;
|
||||
}
|
||||
|
||||
emit(state.copyWith(config: newConfig, selectedIndex: newIndex));
|
||||
}
|
||||
|
||||
/// 切换选中的 Tab
|
||||
void selectTab(int index) {
|
||||
if (index >= 0 && index < state.config.enabledItems.length) {
|
||||
emit(state.copyWith(selectedIndex: index));
|
||||
}
|
||||
}
|
||||
|
||||
/// 重置为默认配置
|
||||
void resetToDefault() {
|
||||
emit(TabConfigState(config: TabConfig.defaultConfig()));
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'dart:convert';
|
||||
@@ -9,8 +10,9 @@ class TabConfigInitial extends TabConfigState {}
|
||||
|
||||
class TabConfigLoaded extends TabConfigState {
|
||||
final TabConfig config;
|
||||
final int selectedIndex;
|
||||
|
||||
TabConfigLoaded(this.config);
|
||||
TabConfigLoaded(this.config, {this.selectedIndex = 0});
|
||||
}
|
||||
|
||||
class TabConfigCubit extends Cubit<TabConfigState> {
|
||||
@@ -22,31 +24,13 @@ class TabConfigCubit extends Cubit<TabConfigState> {
|
||||
}
|
||||
|
||||
void _loadConfig() {
|
||||
try {
|
||||
final configJson = _prefs.getString(_configKey);
|
||||
if (configJson != null) {
|
||||
final List<dynamic> decoded = jsonDecode(configJson);
|
||||
final items = decoded.map((e) {
|
||||
final map = Map<String, dynamic>.from(e);
|
||||
return TabConfigItem(
|
||||
id: map['id'] as String,
|
||||
name: map['name'] as String,
|
||||
nameEn: map['nameEn'] as String,
|
||||
icon: map['icon'] as String,
|
||||
isEnabled: map['isEnabled'] as bool,
|
||||
order: map['order'] as int,
|
||||
);
|
||||
}).toList();
|
||||
emit(TabConfigLoaded(TabConfig(items: items)));
|
||||
} else {
|
||||
final defaultConfig = TabConfig.defaultConfig();
|
||||
_saveConfig(defaultConfig);
|
||||
emit(TabConfigLoaded(defaultConfig));
|
||||
}
|
||||
} catch (e) {
|
||||
final defaultConfig = TabConfig.defaultConfig();
|
||||
emit(TabConfigLoaded(defaultConfig));
|
||||
}
|
||||
debugPrint('🔍 [TabConfigCubit] _loadConfig 被调用');
|
||||
// 直接使用代码中的默认配置,不持久化
|
||||
final defaultConfig = TabConfig.defaultConfig();
|
||||
debugPrint('🔍 [TabConfigCubit] 默认配置 Tab 数量: ${defaultConfig.items.length}');
|
||||
debugPrint('🔍 [TabConfigCubit] 启用的 Tab: ${defaultConfig.enabledItems.map((e) => e.id).toList()}');
|
||||
emit(TabConfigLoaded(defaultConfig));
|
||||
debugPrint('✅ [TabConfigCubit] 状态已 emit');
|
||||
}
|
||||
|
||||
void _saveConfig(TabConfig config) {
|
||||
@@ -70,17 +54,25 @@ class TabConfigCubit extends Cubit<TabConfigState> {
|
||||
final currentState = state as TabConfigLoaded;
|
||||
final newConfig = currentState.config.toggleItem(itemId);
|
||||
|
||||
// 只有配置真正改变时才保存和 emit
|
||||
if (newConfig != currentState.config) {
|
||||
_saveConfig(newConfig);
|
||||
emit(TabConfigLoaded(newConfig));
|
||||
// 不保存,直接更新状态
|
||||
emit(TabConfigLoaded(newConfig, selectedIndex: currentState.selectedIndex));
|
||||
}
|
||||
}
|
||||
|
||||
void selectTab(int index) {
|
||||
if (state is TabConfigLoaded) {
|
||||
final currentState = state as TabConfigLoaded;
|
||||
final enabledTabs = currentState.config.enabledItems;
|
||||
|
||||
// 确保索引在有效范围内
|
||||
if (index >= 0 && index < enabledTabs.length) {
|
||||
emit(TabConfigLoaded(currentState.config, selectedIndex: index));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void resetToDefault() {
|
||||
final defaultConfig = TabConfig.defaultConfig();
|
||||
_saveConfig(defaultConfig);
|
||||
emit(TabConfigLoaded(defaultConfig));
|
||||
}
|
||||
|
||||
|
||||
@@ -5,9 +5,14 @@ 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/v2/home/presentation/pages/home_v2_page.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/home/presentation/bloc/home_v2_bloc.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/device_list/presentation/pages/device_status_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/v2/waring_center/presentation/pages/alarm_center_page.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/waring_center/presentation/bloc/alarm_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/features/my/presentation/pages/my_page.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/my/presentation/pages/my_page.dart' as my_v2;
|
||||
import 'package:maibu_satabot_v2/features/v2/workorder/presentation/pages/workorder_page.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/report/presentation/pages/report_page.dart';
|
||||
import 'package:maibu_satabot_v2/core/di/injection.dart';
|
||||
|
||||
class MainWrapper extends StatefulWidget {
|
||||
@@ -20,6 +25,28 @@ class MainWrapper extends StatefulWidget {
|
||||
class _MainWrapperState extends State<MainWrapper> {
|
||||
int _currentIndex = 0;
|
||||
final PageController _pageController = PageController();
|
||||
final List<GlobalKey> _tabKeys = [];
|
||||
double? _circleLeft;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_updateCirclePosition();
|
||||
});
|
||||
}
|
||||
|
||||
void _updateCirclePosition() {
|
||||
if (_tabKeys.isEmpty || _currentIndex >= _tabKeys.length) return;
|
||||
|
||||
final key = _tabKeys[_currentIndex];
|
||||
final renderBox = key.currentContext?.findRenderObject() as RenderBox?;
|
||||
if (renderBox != null) {
|
||||
setState(() {
|
||||
_circleLeft = renderBox.localToGlobal(Offset.zero).dx;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
@@ -27,16 +54,32 @@ class _MainWrapperState extends State<MainWrapper> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _onTabChanged(int index) {
|
||||
setState(() {
|
||||
_currentIndex = index;
|
||||
});
|
||||
_pageController.jumpToPage(index);
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_updateCirclePosition();
|
||||
});
|
||||
}
|
||||
|
||||
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 'post_add_rounded':
|
||||
return Icons.post_add_rounded;
|
||||
case 'person_rounded':
|
||||
return Icons.person_rounded;
|
||||
default:
|
||||
@@ -44,6 +87,24 @@ class _MainWrapperState extends State<MainWrapper> {
|
||||
}
|
||||
}
|
||||
|
||||
double _getIndicatorPosition(int itemCount, int currentIndex) {
|
||||
final screenWidth = MediaQuery.of(context).size.width;
|
||||
final itemWidth = screenWidth / itemCount;
|
||||
return currentIndex * itemWidth;
|
||||
}
|
||||
|
||||
double _getCircularLeftPosition(int itemCount, int currentIndex) {
|
||||
final screenWidth = MediaQuery.of(context).size.width;
|
||||
final itemWidth = screenWidth / itemCount;
|
||||
// 圆形应该在每个Tab项的中心
|
||||
final tabCenterX = 12 + (currentIndex * itemWidth) + (itemWidth / 2);
|
||||
final circularLeft = tabCenterX - 22; // 22 = 44/2,让圆形中心对齐Tab中心
|
||||
|
||||
// 边界限制
|
||||
final maxLeft = screenWidth - 12 - 44;
|
||||
return circularLeft.clamp(12.0, maxLeft);
|
||||
}
|
||||
|
||||
Widget _buildCurrentPage(TabConfigItem tab) {
|
||||
switch (tab.id) {
|
||||
case 'home_v2':
|
||||
@@ -53,12 +114,23 @@ class _MainWrapperState extends State<MainWrapper> {
|
||||
);
|
||||
case 'home':
|
||||
return const HomePage();
|
||||
case 'device':
|
||||
return const DeviceStatusPage();
|
||||
case 'ai':
|
||||
return const AiPage();
|
||||
case 'warning':
|
||||
return const WarningCenterPage();
|
||||
return BlocProvider(
|
||||
create: (context) => sl<AlarmCubit>(),
|
||||
child: const AlarmCenterPage(),
|
||||
);
|
||||
case 'workorder':
|
||||
return const WorkOrderPage();
|
||||
case 'report':
|
||||
return const ReportPage();
|
||||
case 'my':
|
||||
return const MyPage();
|
||||
case 'me':
|
||||
return const my_v2.MyPage();
|
||||
default:
|
||||
return const HomePage();
|
||||
}
|
||||
@@ -87,8 +159,19 @@ class _MainWrapperState extends State<MainWrapper> {
|
||||
_currentIndex = 0;
|
||||
}
|
||||
|
||||
// 初始化 GlobalKey
|
||||
if (_tabKeys.length != enabledItems.length) {
|
||||
_tabKeys.clear();
|
||||
for (int i = 0; i < enabledItems.length; i++) {
|
||||
_tabKeys.add(GlobalKey());
|
||||
}
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_updateCirclePosition();
|
||||
});
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
extendBody: true,
|
||||
extendBody: false,
|
||||
body: PageView(
|
||||
controller: _pageController,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
@@ -100,57 +183,95 @@ class _MainWrapperState extends State<MainWrapper> {
|
||||
children: enabledItems.map((tab) => _buildCurrentPage(tab)).toList(),
|
||||
),
|
||||
bottomNavigationBar: Container(
|
||||
decoration: BoxDecoration(
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.white,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.08),
|
||||
blurRadius: 10,
|
||||
offset: const Offset(0, -2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: SafeArea(
|
||||
top: false,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: enabledItems.asMap().entries.map((entry) {
|
||||
final index = entry.key;
|
||||
final item = entry.value;
|
||||
final isSelected = _currentIndex == index;
|
||||
|
||||
return Expanded(
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_currentIndex = index;
|
||||
});
|
||||
_pageController.jumpToPage(index);
|
||||
},
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const SizedBox(height: 8),
|
||||
Icon(
|
||||
_getIconData(item.icon),
|
||||
size: 24,
|
||||
color: isSelected ? Colors.blue : Colors.grey,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
item.name,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color: isSelected ? Colors.blue : Colors.grey,
|
||||
fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal,
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 16),
|
||||
padding: const EdgeInsets.symmetric(vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(25),
|
||||
border: Border.all(
|
||||
color: const Color(0xFFE5E6EB),
|
||||
width: 1,
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.05),
|
||||
blurRadius: 10,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Stack(
|
||||
children: [
|
||||
// 滑动圆形背景
|
||||
if (_circleLeft != null)
|
||||
AnimatedPositioned(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
curve: Curves.easeInOut,
|
||||
left: _circleLeft! - 8, // 减去外层 margin + 向右偏移
|
||||
top: 6,
|
||||
child: Container(
|
||||
width: 44,
|
||||
height: 44,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF2F3F5),
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(
|
||||
color: const Color(0xFFE5E6EB),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
),
|
||||
),
|
||||
// Tab 项
|
||||
Row(
|
||||
children: enabledItems.asMap().entries.map((entry) {
|
||||
final index = entry.key;
|
||||
final item = entry.value;
|
||||
final isSelected = _currentIndex == index;
|
||||
|
||||
return Expanded(
|
||||
key: _tabKeys[index],
|
||||
child: InkWell(
|
||||
onTap: () => _onTabChanged(index),
|
||||
child: SizedBox(
|
||||
height: 56,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
_getIconData(item.icon),
|
||||
size: 24,
|
||||
color: isSelected ? const Color(0xFF1D2129) : const Color(0xFF86909C),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
item.name,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color: isSelected ? const Color(0xFF1D2129) : const Color(0xFF86909C),
|
||||
fontWeight: isSelected ? FontWeight.w600 : FontWeight.w400,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -3,11 +3,14 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:maibu_satabot_v2/features/ai/presentation/pages/ai_page.dart';
|
||||
import 'package:maibu_satabot_v2/features/home/presentation/pages/home_page.dart';
|
||||
import 'package:maibu_satabot_v2/features/my/presentation/pages/my_page.dart';
|
||||
import 'package:maibu_satabot_v2/features/main_container/presentation/bloc/tab_config_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/features/main_container/presentation/cubit/tab_config_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/features/main_container/presentation/widgets/custom_bottom_nav_bar.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/home/presentation/pages/home_v2_page.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/device_list/presentation/pages/device_status_page.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/workorder/presentation/pages/workorder_page.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/report/presentation/pages/report_page.dart';
|
||||
|
||||
import '../../../waring_center/presentation/pages/warning_center_page.dart';
|
||||
import '../../../v2/waring_center/presentation/pages/alarm_center_page.dart';
|
||||
|
||||
class CustomMainContainer extends StatefulWidget {
|
||||
const CustomMainContainer({super.key});
|
||||
@@ -16,28 +19,37 @@ class CustomMainContainer extends StatefulWidget {
|
||||
State<CustomMainContainer> createState() => _CustomMainContainerState();
|
||||
}
|
||||
|
||||
class _CustomMainContainerState extends State<CustomMainContainer> with AutomaticKeepAliveClientMixin {
|
||||
class _CustomMainContainerState extends State<CustomMainContainer>
|
||||
with AutomaticKeepAliveClientMixin {
|
||||
@override
|
||||
bool get wantKeepAlive => true; // 保持页面状态
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
|
||||
|
||||
debugPrint('🔍 [CustomMainContainer] build 被调用');
|
||||
|
||||
|
||||
return BlocBuilder<TabConfigCubit, TabConfigState>(
|
||||
builder: (context, state) {
|
||||
if (state is! TabConfigLoaded) {
|
||||
return const Scaffold(
|
||||
body: Center(child: CircularProgressIndicator()),
|
||||
);
|
||||
}
|
||||
|
||||
final enabledTabs = state.config.enabledItems;
|
||||
final currentIndex = state.selectedIndex;
|
||||
|
||||
debugPrint('🔍 [CustomMainContainer] enabledTabs=${enabledTabs.length}, currentIndex=$currentIndex');
|
||||
debugPrint('🔍 [CustomMainContainer] enabledTabs IDs=${enabledTabs.map((e) => e.id).toList()}');
|
||||
|
||||
|
||||
debugPrint(
|
||||
'🔍 [CustomMainContainer] enabledTabs=${enabledTabs.length}, currentIndex=$currentIndex',
|
||||
);
|
||||
debugPrint(
|
||||
'🔍 [CustomMainContainer] enabledTabs IDs=${enabledTabs.map((e) => e.id).toList()}',
|
||||
);
|
||||
|
||||
if (enabledTabs.isEmpty) {
|
||||
return const Scaffold(
|
||||
body: Center(child: Text('请至少启用一个Tab')),
|
||||
);
|
||||
return const Scaffold(body: Center(child: Text('请至少启用一个Tab')));
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
@@ -45,7 +57,21 @@ class _CustomMainContainerState extends State<CustomMainContainer> with Automati
|
||||
index: currentIndex,
|
||||
children: _buildPages(enabledTabs),
|
||||
),
|
||||
bottomNavigationBar: const CustomBottomNavBar(),
|
||||
bottomNavigationBar: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// 调试信息:显示当前 Tab ID
|
||||
Container(
|
||||
color: Colors.yellow.withOpacity(0.8),
|
||||
padding: const EdgeInsets.all(4),
|
||||
child: Text(
|
||||
'当前选中Tab索引: $currentIndex, ID: ${enabledTabs[currentIndex].id}',
|
||||
style: const TextStyle(fontSize: 10, color: Colors.black),
|
||||
),
|
||||
),
|
||||
const CustomBottomNavBar(),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -53,19 +79,32 @@ class _CustomMainContainerState extends State<CustomMainContainer> with Automati
|
||||
|
||||
List<Widget> _buildPages(List<dynamic> enabledTabs) {
|
||||
return enabledTabs.map((tab) {
|
||||
debugPrint('🔍 [buildPages] Tab ID: ${tab.id}, Name: ${tab.name}');
|
||||
switch (tab.id) {
|
||||
case 'home_v2':
|
||||
return const HomeV2Page();
|
||||
case 'home':
|
||||
return const HomePage();
|
||||
debugPrint('✅ 匹配到 home_v2');
|
||||
return const HomeV2Page(key: ValueKey('home_v2'));
|
||||
case 'device':
|
||||
debugPrint('✅ 匹配到 device');
|
||||
return const DeviceStatusPage(key: ValueKey('device'));
|
||||
case 'ai':
|
||||
return const AiPage();
|
||||
debugPrint('✅ 匹配到 ai');
|
||||
return const AiPage(key: ValueKey('ai'));
|
||||
case 'warning':
|
||||
return const WarningCenterPage();
|
||||
debugPrint('✅ 匹配到 warning');
|
||||
return const AlarmCenterPage(key: ValueKey('warning'));
|
||||
case 'workorder':
|
||||
debugPrint('✅ 匹配到 workorder');
|
||||
return const WorkOrderPage(key: ValueKey('workorder'));
|
||||
case 'report':
|
||||
debugPrint('✅ 匹配到 report');
|
||||
return const ReportPage(key: ValueKey('report'));
|
||||
case 'my':
|
||||
return const MyPage();
|
||||
debugPrint('✅ 匹配到 my');
|
||||
return const MyPage(key: ValueKey('my'));
|
||||
default:
|
||||
return const HomePage();
|
||||
debugPrint('❌ 未匹配到 Tab ID: ${tab.id}');
|
||||
return const SizedBox();
|
||||
}
|
||||
}).toList();
|
||||
}
|
||||
|
||||
@@ -68,10 +68,16 @@ class TabSettingsPage extends StatelessWidget {
|
||||
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 'post_add_rounded':
|
||||
return Icons.post_add_rounded;
|
||||
case 'person_rounded':
|
||||
return Icons.person_rounded;
|
||||
default:
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user