FunyMeeAI/lib/features/shell/main_screen.dart
2026-04-14 12:52:56 +08:00

109 lines
3.8 KiB
Dart

import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import '../../core/theme/app_colors.dart';
import '../history/history_screen.dart';
import '../home/home_screen.dart';
import '../profile/profile_screen.dart';
/// 底栏:极淡背景渐变 + 图标/标签 [Shadow],兼顾层次与可读性。
const List<Shadow> _bottomNavItemShadows = [
Shadow(offset: Offset(0, 1), blurRadius: 3, color: Color(0x72000000)),
Shadow(offset: Offset(0, 0), blurRadius: 8, color: Color(0x40000000)),
];
/// Root shell: bottom tabs **Home**, **History**, **Profile** (English labels).
class MainScreen extends StatefulWidget {
const MainScreen({super.key});
@override
State<MainScreen> createState() => _MainScreenState();
}
class _MainScreenState extends State<MainScreen> {
int _index = 0;
@override
Widget build(BuildContext context) {
final parentNav = NavigationBarTheme.of(context);
return Scaffold(
// All tabs: body extends under the bottom bar (faint gradient + [NavigationBar]).
extendBody: true,
body: IndexedStack(
index: _index,
children: [
const HomeScreen(),
HistoryScreen(isRootTab: true, isTabSelected: _index == 1),
const ProfileScreen(isRootTab: true),
],
),
bottomNavigationBar: Stack(
alignment: Alignment.bottomCenter,
children: [
Positioned.fill(
child: DecoratedBox(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
colors: [
AppColors.surface.withValues(alpha: 0.40),
AppColors.surface.withValues(alpha: 0.15),
AppColors.surface.withValues(alpha: 0),
],
stops: const [0.0, 0.48, 1.0],
),
),
),
),
NavigationBarTheme(
data: parentNav.copyWith(
labelTextStyle: WidgetStateProperty.resolveWith((states) {
final selected = states.contains(WidgetState.selected);
return GoogleFonts.inter(
fontSize: 12,
fontWeight: selected ? FontWeight.w600 : FontWeight.w500,
color: selected ? AppColors.primary : AppColors.onSurface,
shadows: _bottomNavItemShadows,
);
}),
iconTheme: WidgetStateProperty.resolveWith((states) {
final selected = states.contains(WidgetState.selected);
return IconThemeData(
color: selected ? AppColors.primary : AppColors.onSurface,
shadows: _bottomNavItemShadows,
);
}),
),
child: NavigationBar(
backgroundColor: Colors.transparent,
elevation: 0,
surfaceTintColor: Colors.transparent,
shadowColor: Colors.transparent,
selectedIndex: _index,
onDestinationSelected: (i) => setState(() => _index = i),
destinations: const [
NavigationDestination(
icon: Icon(Icons.home_outlined),
selectedIcon: Icon(Icons.home_rounded),
label: 'Home',
),
NavigationDestination(
icon: Icon(Icons.history_outlined),
selectedIcon: Icon(Icons.history_rounded),
label: 'History',
),
NavigationDestination(
icon: Icon(Icons.person_outline_rounded),
selectedIcon: Icon(Icons.person_rounded),
label: 'Profile',
),
],
),
),
],
),
);
}
}