162 lines
5.3 KiB
Dart
162 lines
5.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.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/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/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';
|
|
import 'package:maibu_satabot_v2/core/di/injection.dart';
|
|
|
|
class MainWrapper extends StatefulWidget {
|
|
const MainWrapper({super.key});
|
|
|
|
@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 'home_rounded':
|
|
return Icons.home_rounded;
|
|
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_v2':
|
|
return BlocProvider(
|
|
create: (context) => sl<HomeV2Bloc>(),
|
|
child: const HomeV2Page(),
|
|
);
|
|
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 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'),
|
|
),
|
|
);
|
|
}
|
|
|
|
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(
|
|
decoration: 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,
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}).toList(),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|