measure_page_test.dart 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. import 'package:fis_measure/index.dart';
  2. import 'package:fis_measure/interfaces/process/items/measure_terms.dart';
  3. import 'package:fis_measure/interfaces/process/player/play_controller.dart';
  4. import 'package:fis_measure/interfaces/process/workspace/application.dart';
  5. import 'package:fis_measure/interfaces/process/workspace/exam_info.dart';
  6. import 'package:fis_measure/interfaces/process/workspace/measure_controller.dart';
  7. import 'package:fis_measure/process/workspace/measure_controller.dart';
  8. import 'package:fis_measure/view/main/desktop.dart';
  9. import 'package:flutter/material.dart';
  10. import 'package:get/get.dart';
  11. class MeasureTestPage extends StatefulWidget {
  12. const MeasureTestPage({Key? key}) : super(key: key);
  13. @override
  14. State<StatefulWidget> createState() => _MeasureTestPageState();
  15. }
  16. class _MeasureTestPageState extends State<MeasureTestPage> {
  17. static const C_LINEAR_TISSUE =
  18. "http://43.138.119.65:9303/Flyinsono-BJ-1300984704.VCS.AP-BeiJing/9eb581250c6845b7800f0ba00218e043.VID";
  19. static const C_CONVEX_TISSUE =
  20. "http://43.138.119.65:9303/Flyinsono-BJ-1300984704.VCS.AP-BeiJing/9f74db43fd3b4fc486edc59106ae96ae.VID";
  21. final controller = Get.put<IMeasureController>(MeasureController(
  22. "12345",
  23. imagesFetchFunc: (code) async {
  24. return <ExamImageInfo>[
  25. ExamImageInfo(C_LINEAR_TISSUE, C_LINEAR_TISSUE),
  26. ExamImageInfo(C_CONVEX_TISSUE, C_CONVEX_TISSUE)
  27. ];
  28. },
  29. ));
  30. bool loaded = false;
  31. @override
  32. void initState() {
  33. controller.load().then((value) {
  34. // 加载指定图像
  35. controller.examInfo.selectedImageIndex = 0;
  36. });
  37. controller.imageLoaded.addListener(onImageLoaded);
  38. super.initState();
  39. }
  40. @override
  41. void dispose() {
  42. controller.imageLoaded.removeListener(onImageLoaded);
  43. controller.dispose();
  44. Get.delete<IMeasureController>();
  45. super.dispose();
  46. }
  47. void onImageLoaded(Object sender, ExamImageInfo? e) {
  48. if (!mounted) return;
  49. if (e != null) {
  50. setState(() {
  51. loaded = true;
  52. });
  53. }
  54. }
  55. @override
  56. Widget build(BuildContext context) {
  57. Widget body;
  58. if (!loaded) {
  59. const loadingWidget = Center(child: CircularProgressIndicator());
  60. body = Row(
  61. children: const [
  62. SizedBox(
  63. width: 300,
  64. child: loadingWidget,
  65. ),
  66. VerticalDivider(),
  67. Expanded(child: loadingWidget),
  68. ],
  69. );
  70. } else {
  71. body = Row(
  72. key: UniqueKey(),
  73. children: const [
  74. _MeasureLeftBoard(),
  75. VerticalDivider(),
  76. Expanded(
  77. child: _MeasureRightBoard(),
  78. ),
  79. ],
  80. );
  81. }
  82. return Scaffold(
  83. appBar: AppBar(
  84. actions: [
  85. TextButton(
  86. onPressed: () {
  87. if (controller.examInfo.selectedImageIndex == 0) return;
  88. controller.examInfo.selectedImageIndex = 0;
  89. },
  90. child: Text(
  91. '线阵',
  92. style: TextStyle(
  93. color: controller.examInfo.selectedImageIndex == 0
  94. ? Colors.amber
  95. : Colors.white,
  96. ),
  97. ),
  98. ),
  99. TextButton(
  100. onPressed: () {
  101. if (controller.examInfo.selectedImageIndex == 1) return;
  102. controller.examInfo.selectedImageIndex = 1;
  103. },
  104. child: Text(
  105. '扇阵',
  106. style: TextStyle(
  107. color: controller.examInfo.selectedImageIndex == 1
  108. ? Colors.amber
  109. : Colors.white,
  110. ),
  111. ),
  112. ),
  113. ],
  114. leading: IconButton(
  115. onPressed: () {
  116. Navigator.of(context).pop();
  117. },
  118. icon: const Icon(Icons.arrow_back),
  119. ),
  120. ),
  121. body: body,
  122. );
  123. }
  124. }
  125. class _MeasureRightBoard extends StatefulWidget {
  126. const _MeasureRightBoard({Key? key}) : super(key: key);
  127. @override
  128. State<StatefulWidget> createState() => _MeasureRightBoardState();
  129. }
  130. class _MeasureRightBoardState extends State<_MeasureRightBoard> {
  131. final playerController = Get.find<IPlayerController>();
  132. @override
  133. Widget build(BuildContext context) {
  134. return Container(
  135. padding: const EdgeInsets.all(8).copyWith(left: 0),
  136. child: Column(
  137. children: [
  138. const Expanded(
  139. child: MeasureMainView(),
  140. ),
  141. const Divider(),
  142. SizedBox(
  143. height: 150,
  144. child: VidPlayerControlBoard(
  145. playerController as VidPlayerController,
  146. ),
  147. ),
  148. ],
  149. ),
  150. );
  151. }
  152. }
  153. class _MeasureLeftBoard extends StatefulWidget {
  154. const _MeasureLeftBoard({Key? key}) : super(key: key);
  155. @override
  156. State<StatefulWidget> createState() => _MeasureLeftBoardState();
  157. }
  158. class _MeasureLeftBoardState extends State<_MeasureLeftBoard> {
  159. // ignore: non_constant_identifier_names
  160. static final C_SUPPORTED_ITEMS = <String>[
  161. MeasureTerms.Distance,
  162. MeasureTerms.Perimeter,
  163. MeasureTerms.Area,
  164. MeasureTerms.Depth,
  165. ];
  166. final scrollController = ScrollController();
  167. final application = Get.find<IApplication>();
  168. int activeIndex = 0;
  169. @override
  170. void initState() {
  171. application.canMeasureChanged.addListener(_onCanMeasureChanged);
  172. super.initState();
  173. }
  174. @override
  175. dispose() {
  176. application.canMeasureChanged.removeListener(_onCanMeasureChanged);
  177. super.dispose();
  178. }
  179. _onCanMeasureChanged(Object sender, bool e) {
  180. if (e && mounted) {
  181. changeItem(0);
  182. }
  183. }
  184. @override
  185. Widget build(BuildContext context) {
  186. return Container(
  187. width: 300,
  188. padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 12),
  189. child: Scrollbar(
  190. controller: scrollController,
  191. isAlwaysShown: true,
  192. child: ListView.separated(
  193. controller: scrollController,
  194. itemCount: C_SUPPORTED_ITEMS.length,
  195. itemBuilder: (BuildContext context, int index) {
  196. final name = C_SUPPORTED_ITEMS[index];
  197. final active = index == activeIndex;
  198. return active
  199. ? ElevatedButton(
  200. onPressed: () => changeItem(index),
  201. child: Text(name),
  202. style: ElevatedButton.styleFrom(
  203. fixedSize: const Size.fromHeight(50),
  204. ),
  205. )
  206. : OutlinedButton(
  207. onPressed: () => changeItem(index),
  208. child: Text(name),
  209. style: OutlinedButton.styleFrom(
  210. fixedSize: const Size.fromHeight(50),
  211. ),
  212. );
  213. },
  214. separatorBuilder: (BuildContext context, int index) {
  215. return const SizedBox(height: 8);
  216. },
  217. ),
  218. ),
  219. );
  220. }
  221. void changeItem(int index) {
  222. setState(() {
  223. activeIndex = index;
  224. });
  225. final name = C_SUPPORTED_ITEMS[index];
  226. application.switchItemByName(name);
  227. }
  228. }