plugins.dart 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. import 'package:flutter/material.dart';
  2. import 'tools/binomial_distribution.dart';
  3. import 'tools/bisection_method.dart';
  4. import 'tools/chi_square.dart';
  5. import 'tools/circle_equation.dart';
  6. import 'tools/convolution_calculator.dart';
  7. import 'tools/cuo_wei_xiang_jian.dart';
  8. import 'tools/function_plotter.dart';
  9. import 'tools/histogram.dart';
  10. import 'tools/hypergeometric_distribution.dart';
  11. import 'tools/mixed_variance.dart';
  12. import 'tools/parametric_plotter.dart';
  13. import 'tools/regression.dart';
  14. import 'tools/statistical_charts.dart';
  15. import 'tools/symmetry.dart';
  16. import 'tools/vector_normal.dart';
  17. /// 一个数学工具插件。
  18. ///
  19. /// 插件是**编译期**的 Dart 模块 —— Dart 是 AOT 编译的,没有运行时动态加载,
  20. /// 所以"插件"在这里就是「一套接口 + 一张写死的注册表」,加插件要重新编译。
  21. /// 按设计(Q18),用户和 MCP 都不能创建插件,只有开发者能。
  22. @immutable
  23. class ToolPlugin {
  24. /// 显示名,同时用于搜索。
  25. final String name;
  26. final IconData icon;
  27. /// 页面入口。每次导航都新建实例,保证工具状态是干净的。
  28. final Widget Function() build;
  29. /// 命令入口(可选)。
  30. ///
  31. /// 按 Q26b 的约定 **先只做页面入口,命令入口增量补** —— 目前全部为 null。
  32. /// 接命令时,这里填命令名,并在控制台的 _runCommand 里分发。
  33. final String? command;
  34. /// 额外的搜索关键词(拼音首字母等)。
  35. final List<String> keywords;
  36. const ToolPlugin({
  37. required this.name,
  38. required this.icon,
  39. required this.build,
  40. this.command,
  41. this.keywords = const [],
  42. });
  43. bool matches(String q) {
  44. final query = q.trim().toLowerCase();
  45. if (query.isEmpty) return true;
  46. if (name.toLowerCase().contains(query)) return true;
  47. if (command?.toLowerCase().contains(query) ?? false) return true;
  48. return keywords.any((k) => k.toLowerCase().contains(query));
  49. }
  50. }
  51. /// 全部插件。顺序沿用 mathtool2 的注册表。
  52. final List<ToolPlugin> kTools = [
  53. ToolPlugin(
  54. name: '错位相减法',
  55. icon: Icons.functions,
  56. keywords: ['cuowei', 'cwxj', '数列'],
  57. build: () => CuoWeiXiangJianPage(),
  58. ),
  59. ToolPlugin(
  60. name: '二项分布',
  61. icon: Icons.casino_outlined,
  62. keywords: ['binomial', 'exbf', '概率'],
  63. build: () => BinomialDistributionPage(),
  64. ),
  65. ToolPlugin(
  66. name: '超几何分布',
  67. icon: Icons.pie_chart_outline,
  68. keywords: ['hypergeometric', 'cjhf', '概率'],
  69. build: () => HypergeometricDistributionPage(),
  70. ),
  71. ToolPlugin(
  72. name: '卷积分布列',
  73. icon: Icons.layers_outlined,
  74. keywords: ['convolution', 'juanji', 'jj'],
  75. build: () => ConvolutionCalculatorPage(),
  76. ),
  77. ToolPlugin(
  78. name: '卡方检验',
  79. icon: Icons.rule,
  80. keywords: ['chi square', 'kfjy', '统计'],
  81. build: () => ChiSquarePage(),
  82. ),
  83. ToolPlugin(
  84. name: '线性回归',
  85. icon: Icons.show_chart,
  86. keywords: ['regression', 'xxhg', '统计'],
  87. build: () => RegressionPage(),
  88. ),
  89. ToolPlugin(
  90. name: '混合方差',
  91. icon: Icons.balance_outlined,
  92. keywords: ['variance', 'hhfc', '统计'],
  93. build: () => MixedVariancePage(),
  94. ),
  95. ToolPlugin(
  96. name: '直方图统计',
  97. icon: Icons.bar_chart,
  98. keywords: ['histogram', 'zft', '统计'],
  99. build: () => HistogramPage(),
  100. ),
  101. ToolPlugin(
  102. name: '统计图表',
  103. icon: Icons.area_chart,
  104. keywords: ['chart', 'tjth', '图表'],
  105. build: () => StatisticalChartsPage(),
  106. ),
  107. ToolPlugin(
  108. name: '对称变换',
  109. icon: Icons.swap_horiz,
  110. keywords: ['symmetry', 'dcbh', '几何'],
  111. build: () => SymmetryPage(),
  112. ),
  113. ToolPlugin(
  114. name: '圆的方程',
  115. icon: Icons.circle_outlined,
  116. keywords: ['circle', 'ydfc', '几何'],
  117. build: () => CircleEquationPage(),
  118. ),
  119. ToolPlugin(
  120. name: '三点法向量',
  121. icon: Icons.view_in_ar_outlined,
  122. keywords: ['normal', 'sdfxl', '向量', '立体几何'],
  123. build: () => VectorNormalPage(),
  124. ),
  125. ToolPlugin(
  126. name: '二分法求根',
  127. icon: Icons.search,
  128. keywords: ['bisection', 'effqg', '求根'],
  129. build: () => BisectionMethodPage(),
  130. ),
  131. ToolPlugin(
  132. name: '函数图像绘制',
  133. icon: Icons.timeline,
  134. keywords: ['plot', 'hstx', '绘图'],
  135. build: () => FunctionPlotterPage(),
  136. ),
  137. ToolPlugin(
  138. name: '参数方程绘图',
  139. icon: Icons.gesture,
  140. keywords: ['parametric', 'csfc', '绘图'],
  141. build: () => ParametricPlotterPage(),
  142. ),
  143. ];