import 'package:fis_common/logger/logger.dart'; import 'package:fis_measure/interfaces/process/items/item.dart'; import 'package:fis_measure/interfaces/process/items/item_metas.dart'; import 'package:fis_measure/interfaces/process/player/play_controller.dart'; import 'package:fis_measure/interfaces/process/workspace/application.dart'; import 'package:fis_measure/process/items/item_meta_convert.dart'; import 'package:fis_measure/process/workspace/measure_data_controller.dart'; import 'package:fis_measure/process/workspace/measure_handler.dart'; import 'package:fis_measure/view/player/controller.dart'; import 'package:fis_ui/index.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:vid/us/vid_us_image.dart'; /// 测量项页面 class LeftSiderSelectMeasure extends FStatefulWidget { const LeftSiderSelectMeasure({Key? key}) : super(key: key); @override FState createState() => LeftSiderSelectMeasureState(); } class LeftSiderSelectMeasureState extends FState { final ScrollController scrollController = ScrollController(); late final application = Get.find(); late final measureHandler = Get.find(); /// 数据 late final measureData = Get.find(); final playerController = Get.find() as VidPlayerController; // final topMeasureItem = Get.put(); /// 当前选中的测量项目 String activeName = ''; /// 当前组合测量项 ItemMeta? comboItemMeta; int? comboItemMetaActivedIndex; /// 是否展开组合测量项 bool isCombo = false; void workingChildChanged(sender, int e) { comboItemMetaActivedIndex = e; setState(() {}); } /// 切换测量项 void changeItem(ItemMeta itemMeta) { activeName = itemMeta.name; try { application.switchItem(itemMeta); final item = application.activeMeasureItem!; if (item is ITopMeasureItem) { item.switchChild(0); item.workingChildChanged.addListener(workingChildChanged); } } catch (e) { logger.e("changeItem failed", e); } if (mounted) { setState(() {}); } } /// 当前测量数据源变更 void itemMetaList(Object s, dynamic e) { try { if (e != null) { setState(() {}); } } catch (e) { debugPrint("callmethod fail " + e.toString()); } } /// 获取组合测量项 void comboList() { /// 格式化数据 List itemMetaList = []; for (var element in measureData.itemMetaList) { if (measureData.getMeasureApplicationList.contains(element.name)) { itemMetaList.add(element); } } measureData.getItemMetaList = itemMetaList; measureData.getTopItemMetaList = measureData.getItemMetaList; } /// 获取当前图像的测量项,从第一帧取 void currentFrameHandler(Object sender, VidUsImage e) async { List getModes = []; for (var element in e.visuals[0].modes) { getModes.add(element.type.toString().split('.')[1]); } measureData.applicationModes = e.visuals[0].modes; measureData.currentMode = e.visuals[0].modes.first.type.name; var measureModeSelection = MeasureModeSelection( application.applicationName, application.categoryName, application.isThirdPart ? ['TPPTissue'] : getModes, ); measureHandler.measureModeChanged = measureModeSelection; var measureApplicationDTO = await measureData.getMeasureApplication.call(measureModeSelection); if (measureApplicationDTO != null) { /// 模式版本 measureData.measureApplicationVersion = measureApplicationDTO.version ?? ''; measureData.availableModes = measureApplicationDTO.availableModes ?? []; ///模式列表 var models = measureApplicationDTO.availableModes; if (models != null && models.isNotEmpty) { ///群组列表 var groups = models[0].availableGroups; if (groups != null && groups.isNotEmpty) { ///项目列表 var folders = groups[0].availableFolders; if (folders != null && folders.isNotEmpty) { measureData.getMeasureApplicationList = folders[0].workingItemNames ?? []; if (folders[0].availableItems != null) { measureData.itemMetaList = folders[0].availableItems!.map((element) { return ItemMetaConverter(element).output(); }).toList(); comboList(); } print('测量方法集: ${measureData.getMeasureApplicationList.toString()}'); if (measureData.getMeasureApplicationList.isNotEmpty) { changeItem(measureData.getItemMetaList[0]); } } } } } getNoteCommentsList(); } /// 注释获取 void getNoteCommentsList() async { List commentsList = []; var measureCommentItemResult = await measureData.getCommentsByApplicationAsync( application.applicationName, application.categoryName, ); measureData.measureCommentItemResult = measureCommentItemResult?.commentItems ?? []; measureCommentItemResult?.commentItems?.forEach((element) { commentsList.add(element.text ?? ''); }); measureData.getCommentsList = commentsList; } void getItemMetaListChanged(sender, e) { measureData.getTopItemMetaList = measureData.getItemMetaList; setState(() {}); } @override void initState() { playerController.currentFrameHandler.addListener( (currentFrameHandler), ); measureData.getItemMetaListChanged.addListener(getItemMetaListChanged); measureData.itemMetaListChanged.addListener(itemMetaList); super.initState(); } @override dispose() { super.dispose(); playerController.currentFrameHandler.removeListener( (currentFrameHandler), ); measureData.getItemMetaListChanged.removeListener(getItemMetaListChanged); measureData.itemMetaListChanged.removeListener(itemMetaList); final item = application.activeMeasureItem!; if (item is ITopMeasureItem) { item.workingChildChanged.removeListener(workingChildChanged); } } @override FWidget build(BuildContext context) { return FSingleChildScrollView( controller: ScrollController(), child: FScrollbar( isAlwaysShown: true, child: FColumn( children: [ _buildFGridView(measureData.getTopItemMetaList), if (isCombo) _buildCombo(), _buildFGridView(measureData.getBottomItemMetaList), ], ), ), ); } /// 未选中的普通测量项 选中事件 void chooseMeasure(ItemMeta itemMeta) { isCombo = false; changeItem(itemMeta); measureData.getTopItemMetaList = measureData.getItemMetaList; measureData.getBottomItemMetaList = []; } void chooseComboMeasure(ItemMeta itemMeta) { isCombo = true; changeItem(itemMeta); List top = []; List bottom = []; List getItemMetaList = measureData.getItemMetaList; for (int i = 0; i < getItemMetaList.length; i++) { if (i <= getItemMetaList.indexOf(itemMeta)) { top.add(getItemMetaList[i]); } else { bottom.add(getItemMetaList[i]); } measureData.getTopItemMetaList = top; measureData.getBottomItemMetaList = bottom; if (i == getItemMetaList.indexOf(itemMeta)) { comboItemMeta = getItemMetaList[i]; comboItemMetaActivedIndex = 0; } } } FWidget _buildComboItem(ItemMeta itemMeta, int index) { FWidget child; if (comboItemMetaActivedIndex == index) { child = FElevatedButton( onPressed: () { final item = application.activeMeasureItem!; if (item is ITopMeasureItem) { item.switchChild(index); comboItemMetaActivedIndex = index; } setState(() {}); }, child: FText( itemMeta.name, style: const TextStyle( color: Colors.white, ), ), ); } else { child = FOutlinedButton( onPressed: () { final item = application.activeMeasureItem!; if (item is ITopMeasureItem) { item.switchChild(index); comboItemMetaActivedIndex = index; } setState(() {}); }, style: OutlinedButton.styleFrom( side: const BorderSide( color: Color.fromRGBO(124, 124, 124, 1), ), ), child: FText( itemMeta.name, style: const TextStyle( color: Colors.white, ), ), ); } return child; } /// 组合测量项打开的ui FWidget _buildCombo() { return FColumn( mainAxisSize: MainAxisSize.max, children: [ FContainer( padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 5), color: const Color.fromRGBO(70, 70, 70, 1), child: FColumn( children: (comboItemMeta?.childItems ?? []) .asMap() .entries .map( (e) => FContainer( width: double.infinity, padding: const EdgeInsets.symmetric( vertical: 2, ), child: _buildComboItem( e.value, e.key, ), ), ) .toList(), ), ), ], ); } FWidget _buildFGridView(List itemMeta) { return FGridView.count( shrinkWrap: true, crossAxisCount: 2, childAspectRatio: 3, controller: ScrollController(), children: itemMeta.map((e) { if (e.name == activeName) { // 选中的测量项 return _buildItemMetaContainer(e, () {}); } else { if (e.childItems.isEmpty) { return _buildItemMetaContainer( e, () => chooseMeasure(e), ); } else { return _buildItemMetaContainer( e, () => chooseComboMeasure(e), ); } } }).toList(), ); } FWidget _buildItemMetaContainer(ItemMeta e, Function onTap) { FWidget measure; if (e.name == activeName) { measure = FElevatedButton( onPressed: () => onTap.call(), child: FText(e.name), style: ElevatedButton.styleFrom( fixedSize: const Size.fromHeight( 40, ), ), ); } else { measure = FOutlinedButton( onPressed: () => onTap.call(), child: FText( e.name, style: const TextStyle( color: Colors.white, ), ), style: OutlinedButton.styleFrom( fixedSize: const Size.fromHeight( 40, ), side: const BorderSide( color: Color.fromRGBO(124, 124, 124, 1), ), textStyle: const TextStyle( color: Colors.white, ), ), ); } return FRow( children: [ const FSizedBox( width: 12, ), FExpanded( child: measure, ), const FSizedBox( width: 12, ), ], ); } }