import 'package:flutter/material.dart'; import 'pages/account_page.dart'; import 'pages/manage_page.dart'; import 'pages/stats_page.dart'; import 'pages/study_page.dart'; /// 应用外壳:底部四个主入口。 /// /// 用 [IndexedStack] 而不是直接切换 widget,是为了在切页时保留各页面的 /// 状态(滚动位置、输入内容、进行中的学习会话)。 class AppShell extends StatefulWidget { const AppShell({super.key}); @override State createState() => _AppShellState(); } class _AppShellState extends State { int _selectedIndex = 0; static const List _pages = [ StudyPage(), ManagePage(), StatsPage(), AccountPage(), ]; @override Widget build(BuildContext context) { return Scaffold( body: IndexedStack(index: _selectedIndex, children: _pages), bottomNavigationBar: NavigationBar( selectedIndex: _selectedIndex, onDestinationSelected: (int index) { setState(() => _selectedIndex = index); }, destinations: const [ NavigationDestination( icon: Icon(Icons.school_outlined), selectedIcon: Icon(Icons.school), label: '学习', ), NavigationDestination( icon: Icon(Icons.library_books_outlined), selectedIcon: Icon(Icons.library_books), label: '管理', ), NavigationDestination( icon: Icon(Icons.insights_outlined), selectedIcon: Icon(Icons.insights), label: '统计', ), NavigationDestination( icon: Icon(Icons.person_outline), selectedIcon: Icon(Icons.person), label: '账户', ), ], ), ); } }