import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:shadcn_ui/shadcn_ui.dart'; import '../data/providers.dart'; import '../routing/app_routes.dart'; import '../theme/yanting_text.dart'; import '../widgets/bottom_tab_bar.dart'; import '../widgets/mini_player.dart'; class ShellPage extends ConsumerWidget { const ShellPage({required this.child, required this.currentPath, super.key}); final Widget child; final String currentPath; @override Widget build(BuildContext context, WidgetRef ref) { final theme = ShadTheme.of(context); final player = ref.watch(audioPlayerControllerProvider); final controller = ref.read(audioPlayerControllerProvider.notifier); final canPop = GoRouter.of(context).canPop(); final selectedIndex = _tabs.indexWhere((tab) => tab.path == currentPath); final safeIndex = selectedIndex < 0 ? 0 : selectedIndex; return Scaffold( backgroundColor: theme.colorScheme.background, appBar: AppBar( backgroundColor: theme.colorScheme.background, surfaceTintColor: Colors.transparent, elevation: 0, leading: canPop ? ShadIconButton.ghost( onPressed: () => context.pop(), icon: const Icon(LucideIcons.chevronLeft, size: 18), ) : null, title: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text('研听', style: YantingText.listTitle), Text('全球机构研报中文解读', style: YantingText.meta.copyWith(fontSize: 12)), ], ), bottom: PreferredSize( preferredSize: const Size.fromHeight(1), child: ColoredBox( color: theme.colorScheme.border, child: const SizedBox(height: 1, width: double.infinity), ), ), ), body: ColoredBox( color: theme.colorScheme.background, child: Stack(children: [Positioned.fill(child: child)]), ), bottomNavigationBar: SafeArea( top: false, child: Column( mainAxisSize: MainAxisSize.min, children: [ MiniPlayer(player: player, onToggle: controller.toggleAudio), BottomTabBar( items: yantingBottomTabItems, selectedIndex: safeIndex, onSelected: (index) => context.go(_tabs[index].path), ), ], ), ), ); } } class _TabItem { const _TabItem({required this.path}); final String path; } const List<_TabItem> _tabs = [ _TabItem(path: AppRoutes.home), _TabItem(path: AppRoutes.reports), _TabItem(path: AppRoutes.institutions), _TabItem(path: AppRoutes.listen), _TabItem(path: AppRoutes.profile), ];