mobile_top_menu.dart 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. import 'package:fis_measure/interfaces/enums/annotation.dart';
  2. import 'package:fis_measure/interfaces/process/workspace/application.dart';
  3. import 'package:fis_measure/interfaces/process/workspace/mobile_measure_view_state_controller.dart';
  4. import 'package:fis_measure/process/workspace/measure_handler.dart';
  5. import 'package:fis_measure/view/mobile_view/controller/mobile_measure_view_state_controller.dart';
  6. import 'package:fis_measure/view/mobile_view/widgets/animated_icon_btn.dart';
  7. import 'package:fis_measure/view/mobile_view/widgets/icon_btn.dart';
  8. import 'package:flutter/material.dart';
  9. import 'package:get/get.dart';
  10. class MobileTopMenu extends StatefulWidget {
  11. final VoidCallback capturePng;
  12. const MobileTopMenu({
  13. Key? key,
  14. required this.capturePng,
  15. }) : super(key: key);
  16. @override
  17. State<StatefulWidget> createState() => _MobileTopMenuState();
  18. }
  19. class _MobileTopMenuState extends State<MobileTopMenu> {
  20. final application = Get.find<IApplication>();
  21. final measureHandler = Get.find<MeasureHandler>();
  22. final mobileMeasureStateController =
  23. Get.find<MobileMeasureViewStateController>();
  24. @override
  25. void initState() {
  26. mobileMeasureStateController.onModeChanged.addListener(_onViewModeChanged);
  27. super.initState();
  28. }
  29. @override
  30. void dispose() {
  31. mobileMeasureStateController.onModeChanged
  32. .removeListener(_onViewModeChanged);
  33. super.dispose();
  34. }
  35. MobileMeasureMode curMode = MobileMeasureMode.playerMode;
  36. void _onViewModeChanged(Object s, MobileMeasureMode mode) {
  37. setState(() {
  38. curMode = mode;
  39. });
  40. }
  41. @override
  42. Widget build(BuildContext context) {
  43. return Column(
  44. mainAxisSize: MainAxisSize.max,
  45. mainAxisAlignment: MainAxisAlignment.start,
  46. children: [
  47. SizedBox(
  48. height: 50,
  49. child: Container(
  50. padding: const EdgeInsets.only(left: 10),
  51. child: Row(
  52. mainAxisAlignment: MainAxisAlignment.start,
  53. children: [
  54. ..._buttons(),
  55. ],
  56. ),
  57. ),
  58. ),
  59. ],
  60. );
  61. }
  62. List<Widget> _buttons() {
  63. switch (curMode) {
  64. case MobileMeasureMode.playerMode:
  65. return [
  66. _fillCustomSpace(10),
  67. _backBtn(),
  68. _fillEmptySpace(),
  69. _saveBtn(),
  70. _editBtn(),
  71. _shareBtn(),
  72. _fillCustomSpace(150)
  73. ];
  74. case MobileMeasureMode.measureMode:
  75. return [
  76. _exitBtn(),
  77. const Text('测量模式'),
  78. _fillEmptySpace(),
  79. _saveBtn(),
  80. _deleteBtn(),
  81. _undoBtn(),
  82. ];
  83. case MobileMeasureMode.annotationMode:
  84. return [
  85. _exitBtn(),
  86. const Text('注释模式'),
  87. _fillEmptySpace(),
  88. _annotationBtn(),
  89. _arrowBtn(),
  90. _saveBtn(),
  91. _deleteBtn(),
  92. _undoBtn(),
  93. ];
  94. default:
  95. return [Container()];
  96. }
  97. }
  98. Widget _saveBtn() {
  99. return LoadingAnimatedIconButton(
  100. icon: Icons.save,
  101. onPressed: () {
  102. widget.capturePng();
  103. },
  104. );
  105. }
  106. Widget _shareBtn() {
  107. return SingleIconButton(
  108. icon: Icons.share,
  109. onPressed: () {
  110. print("call 分享");
  111. },
  112. );
  113. }
  114. Widget _editBtn() {
  115. return SingleIconButton(
  116. icon: Icons.edit,
  117. onPressed: () {
  118. print("call 进入撰写报告");
  119. },
  120. );
  121. }
  122. Widget _backBtn() {
  123. return SingleIconButton(
  124. icon: Icons.arrow_back_ios_new,
  125. onPressed: () {
  126. print("call 返回");
  127. },
  128. );
  129. }
  130. Widget _exitBtn() {
  131. return SingleIconButton(
  132. icon: Icons.exit_to_app,
  133. onPressed: () {
  134. print("call 退出当前模式");
  135. mobileMeasureStateController.currentMode = MobileMeasureMode.playerMode;
  136. },
  137. );
  138. }
  139. Widget _annotationBtn() {
  140. return SingleIconButton(
  141. icon: Icons.abc,
  142. onPressed: () {
  143. print("call 注释模式");
  144. },
  145. );
  146. }
  147. Widget _arrowBtn() {
  148. // bool get isArrowMeasureAnnotationType =>
  149. // measureHandler.changedAnnotationType == AnnotationType.arrow;
  150. // TODO 原本是用于判断当前是否为箭头模式
  151. return SingleIconButton(
  152. icon: Icons.compare_arrows_rounded,
  153. onPressed: () {
  154. print("call 箭头模式");
  155. measureHandler.changedAnnotationType =
  156. AnnotationType.arrow; // TODO 原本是用于判断当前是否为箭头模式
  157. application.switchAnnotation(AnnotationType.arrow);
  158. },
  159. );
  160. }
  161. Widget _deleteBtn() {
  162. return SingleIconButton(
  163. icon: Icons.delete_outline,
  164. onPressed: () {
  165. application.clearRecords();
  166. },
  167. );
  168. }
  169. Widget _undoBtn() {
  170. return SingleIconButton(
  171. icon: Icons.redo,
  172. onPressed: () {
  173. application.undoRecord();
  174. },
  175. );
  176. }
  177. Widget _fillEmptySpace() {
  178. return Expanded(
  179. child: SizedBox(
  180. height: 1,
  181. width: MediaQuery.of(context).size.width,
  182. ),
  183. );
  184. }
  185. Widget _fillCustomSpace(double width) {
  186. return SizedBox(
  187. width: width,
  188. );
  189. }
  190. }