measure_page_test.dart 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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://192.168.6.117:9303/Flyinsono-BJ-1300984704.VCS.AP-BeiJing/151394487066498fbb8f1e34ca0c7083.VID";
  19. static const C_CONVEX_TISSUE =
  20. "http://192.168.6.117:9001/Flyinsono-BJ-1300984704.VCS.AP-BeiJing/default.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. super.initState();
  38. WidgetsBinding.instance!.addPostFrameCallback((timeStamp) {
  39. controller.imageLoaded.addListener(onImageLoaded);
  40. });
  41. }
  42. @override
  43. void dispose() {
  44. controller.imageLoaded.removeListener(onImageLoaded);
  45. controller.dispose();
  46. Get.delete<IMeasureController>();
  47. super.dispose();
  48. }
  49. void onImageLoaded(Object sender, ExamImageInfo? e) {
  50. if (e != null) {
  51. setState(() {
  52. loaded = true;
  53. });
  54. }
  55. }
  56. @override
  57. Widget build(BuildContext context) {
  58. Widget body;
  59. if (!loaded) {
  60. const loadingWidget = Center(child: CircularProgressIndicator());
  61. body = Row(
  62. children: const [
  63. SizedBox(
  64. width: 300,
  65. child: loadingWidget,
  66. ),
  67. VerticalDivider(),
  68. Expanded(child: loadingWidget),
  69. ],
  70. );
  71. } else {
  72. body = Row(
  73. children: const [
  74. _MeasureLeftBoard(),
  75. VerticalDivider(),
  76. Expanded(
  77. child: _MeasureRightBoard(),
  78. ),
  79. ],
  80. );
  81. }
  82. return Scaffold(
  83. appBar: AppBar(),
  84. body: body,
  85. );
  86. }
  87. }
  88. class _MeasureRightBoard extends StatefulWidget {
  89. const _MeasureRightBoard({Key? key}) : super(key: key);
  90. @override
  91. State<StatefulWidget> createState() => _MeasureRightBoardState();
  92. }
  93. class _MeasureRightBoardState extends State<_MeasureRightBoard> {
  94. final playerController = Get.find<IPlayerController>();
  95. @override
  96. Widget build(BuildContext context) {
  97. return Container(
  98. padding: const EdgeInsets.all(8).copyWith(left: 0),
  99. child: Column(
  100. children: [
  101. const Expanded(
  102. child: MeasureMainView(),
  103. ),
  104. const Divider(),
  105. SizedBox(
  106. height: 140,
  107. child: VidPlayerControlBoard(
  108. playerController as VidPlayerController,
  109. ),
  110. ),
  111. ],
  112. ),
  113. );
  114. }
  115. }
  116. class _MeasureLeftBoard extends StatefulWidget {
  117. const _MeasureLeftBoard({Key? key}) : super(key: key);
  118. @override
  119. State<StatefulWidget> createState() => _MeasureLeftBoardState();
  120. }
  121. class _MeasureLeftBoardState extends State<_MeasureLeftBoard> {
  122. // ignore: non_constant_identifier_names
  123. static final C_SUPPORTED_ITEMS = <String>[
  124. MeasureTerms.Distance,
  125. MeasureTerms.Perimeter,
  126. MeasureTerms.Area,
  127. ];
  128. final scrollController = ScrollController();
  129. final application = Get.find<IApplication>();
  130. int activeIndex = 0;
  131. @override
  132. void initState() {
  133. application.canMeasureChanged.addListener(_onCanMeasureChanged);
  134. super.initState();
  135. }
  136. @override
  137. dispose() {
  138. application.canMeasureChanged.removeListener(_onCanMeasureChanged);
  139. super.dispose();
  140. }
  141. _onCanMeasureChanged(Object sender, bool e) {
  142. if (e && mounted) {
  143. changeItem(0);
  144. }
  145. }
  146. @override
  147. Widget build(BuildContext context) {
  148. return Container(
  149. width: 300,
  150. padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 12),
  151. child: Scrollbar(
  152. controller: scrollController,
  153. isAlwaysShown: true,
  154. child: ListView.separated(
  155. controller: scrollController,
  156. itemCount: C_SUPPORTED_ITEMS.length,
  157. itemBuilder: (BuildContext context, int index) {
  158. final name = C_SUPPORTED_ITEMS[index];
  159. final active = index == activeIndex;
  160. return active
  161. ? ElevatedButton(
  162. onPressed: () => changeItem(index),
  163. child: Text(name),
  164. style: ElevatedButton.styleFrom(
  165. fixedSize: const Size.fromHeight(50),
  166. ),
  167. )
  168. : OutlinedButton(
  169. onPressed: () => changeItem(index),
  170. child: Text(name),
  171. style: OutlinedButton.styleFrom(
  172. fixedSize: const Size.fromHeight(50),
  173. ),
  174. );
  175. },
  176. separatorBuilder: (BuildContext context, int index) {
  177. return const SizedBox(height: 8);
  178. },
  179. ),
  180. ),
  181. );
  182. }
  183. void changeItem(int index) {
  184. setState(() {
  185. activeIndex = index;
  186. });
  187. final name = C_SUPPORTED_ITEMS[index];
  188. print(name);
  189. application.switchItemByName(name);
  190. }
  191. }