164 lines
5.4 KiB
Dart
164 lines
5.4 KiB
Dart
import 'dart:ui';
|
|
import 'package:flutter/material.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 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 '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 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(
|
|
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: 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(),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|