main.dart 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import 'package:flutter/material.dart';
  2. import 'package:provider/provider.dart';
  3. import 'calculator_page.dart';
  4. import 'console_page.dart';
  5. import 'symja.dart';
  6. import 'tools_page.dart';
  7. void main() => runApp(const CalApp());
  8. class CalApp extends StatelessWidget {
  9. const CalApp({super.key});
  10. @override
  11. Widget build(BuildContext context) {
  12. return ChangeNotifierProvider(
  13. create: (_) => SymjaSession(),
  14. child: MaterialApp(
  15. title: '某人的计算器2',
  16. debugShowCheckedModeBanner: false,
  17. theme: ThemeData(colorSchemeSeed: Colors.indigo, useMaterial3: true),
  18. home: const ShellPage(),
  19. ),
  20. );
  21. }
  22. }
  23. /// 三个界面(Q16 的「双界面」+ 插件页):
  24. /// 计算器 —— 默认入口,卡西欧式按键
  25. /// 工具 —— 16 个插件的网格入口
  26. /// 控制台 —— 表达式 REPL
  27. ///
  28. /// 用 IndexedStack 保住各页状态:切回来时控制台的历史、计算器正在输入的
  29. /// 表达式都还在。
  30. class ShellPage extends StatefulWidget {
  31. const ShellPage({super.key});
  32. @override
  33. State<ShellPage> createState() => _ShellPageState();
  34. }
  35. class _ShellPageState extends State<ShellPage> {
  36. int _index = 0;
  37. @override
  38. Widget build(BuildContext context) {
  39. return Scaffold(
  40. body: IndexedStack(
  41. index: _index,
  42. children: const [
  43. CalculatorPage(),
  44. ToolsPage(),
  45. ConsolePage(),
  46. ],
  47. ),
  48. bottomNavigationBar: NavigationBar(
  49. selectedIndex: _index,
  50. onDestinationSelected: (i) => setState(() => _index = i),
  51. destinations: const [
  52. NavigationDestination(
  53. icon: Icon(Icons.calculate_outlined),
  54. selectedIcon: Icon(Icons.calculate),
  55. label: '计算器',
  56. ),
  57. NavigationDestination(
  58. icon: Icon(Icons.widgets_outlined),
  59. selectedIcon: Icon(Icons.widgets),
  60. label: '工具',
  61. ),
  62. NavigationDestination(
  63. icon: Icon(Icons.terminal_outlined),
  64. selectedIcon: Icon(Icons.terminal),
  65. label: '控制台',
  66. ),
  67. ],
  68. ),
  69. );
  70. }
  71. }