button_group.dart 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. import 'dart:async';
  2. import 'package:fis_i18n/i18n.dart';
  3. import 'package:fis_jsonrpc/rpc.dart';
  4. import 'package:fis_measure/interfaces/process/standard_line/calibration.dart';
  5. import 'package:fis_measure/interfaces/process/workspace/application.dart';
  6. import 'package:fis_measure/process/workspace/measure_data_controller.dart';
  7. import 'package:fis_measure/process/workspace/measure_handler.dart';
  8. import 'package:fis_measure/utils/prompt_box.dart';
  9. import 'package:fis_measure/view/button_group/widget/qr_code_with_logo.dart';
  10. import 'package:fis_measure/view/paint/ai_patint_controller.dart';
  11. import 'package:fis_ui/index.dart';
  12. import 'package:flutter/material.dart';
  13. import 'package:get/get.dart';
  14. import 'package:url_launcher/url_launcher.dart';
  15. class ButtonGroup extends StatefulWidget {
  16. final VoidCallback capturePng;
  17. const ButtonGroup({
  18. Key? key,
  19. required this.capturePng,
  20. }) : super(key: key);
  21. @override
  22. State<ButtonGroup> createState() => _ButtonGroupState();
  23. }
  24. class _ButtonGroupState extends State<ButtonGroup> {
  25. double _width = 0;
  26. bool _isExpanded = false;
  27. final _key = GlobalKey();
  28. final application = Get.find<IApplication>();
  29. /// 数据
  30. final measureData = Get.find<MeasureDataController>();
  31. late final measureHandler = Get.find<MeasureHandler>();
  32. late final aiPatintController = Get.find<AiPatintController>();
  33. late bool canShowAI = [
  34. DiagnosisConclusionEnum.Benign,
  35. DiagnosisConclusionEnum.Malignant,
  36. DiagnosisConclusionEnum.BenignAndMalignant
  37. ].contains(measureData.diagnosisConclusion);
  38. List<Widget> buildTitleButtonList() {
  39. return [
  40. _buildTitleButton(
  41. FIcons.fis_quash,
  42. i18nBook.common.revoke.t,
  43. () => application.undoRecord(),
  44. ),
  45. _buildTitleButton(
  46. FIcons.fis_purge,
  47. i18nBook.measure.clear.t,
  48. () => application.clearRecords(),
  49. ),
  50. _buildTitleButton(
  51. measureHandler.fullScreenState
  52. ? FIcons.fis_full_screen_reduction
  53. : FIcons.fis_full_screen,
  54. measureHandler.fullScreenState
  55. ? i18nBook.common.cancel.t + i18nBook.measure.fullScreen.t
  56. : i18nBook.measure.fullScreen.t,
  57. () {
  58. measureHandler.fullScreenState = !measureHandler.fullScreenState;
  59. setState(() {});
  60. },
  61. ),
  62. _buildTitleButton(
  63. FIcons.fis_save,
  64. i18nBook.common.save.t,
  65. widget.capturePng,
  66. ),
  67. _buildTitleButton(
  68. FIcons.fis_share,
  69. i18nBook.remedical.share.t,
  70. () async {
  71. var itemCurrentImage = await measureData.shareImage.call(
  72. measureData.itemCurrentImage,
  73. );
  74. Get.dialog(_buildShareQr(itemCurrentImage));
  75. },
  76. ),
  77. if (application.isThirdPart) ...[
  78. _buildTitleButton(
  79. FIcons.device,
  80. i18nBook.remedical.calibrationLine.t,
  81. () {
  82. Get.find<IStandardLineCalibrationController>().enterEditMode();
  83. },
  84. ),
  85. ],
  86. if (canShowAI) ...[
  87. _buildTitleButton(
  88. !aiPatintController.state.isShowAi
  89. ? FIcons.fis_eye_display
  90. : FIcons.fis_eye_hidden,
  91. !aiPatintController.state.isShowAi
  92. ? i18nBook.measure.showAi.t
  93. : i18nBook.measure.hideAi.t,
  94. () {
  95. aiPatintController.state.isShowAi =
  96. !aiPatintController.state.isShowAi;
  97. setState(() {});
  98. },
  99. ),
  100. ]
  101. ];
  102. }
  103. @override
  104. Widget build(BuildContext context) {
  105. return Row(
  106. mainAxisAlignment: MainAxisAlignment.end,
  107. children: [
  108. InkWell(
  109. onTap: () {},
  110. onHover: (isHover) {
  111. if (!isHover) {
  112. setState(() {
  113. _width = 0;
  114. _isExpanded = isHover;
  115. });
  116. } else {
  117. setState(() {
  118. // application.isThirdPart ? _width = 270 : _width = 220;
  119. _width = buildTitleButtonList().length * 48;
  120. _isExpanded = isHover;
  121. });
  122. }
  123. },
  124. child: AnimatedContainer(
  125. duration: const Duration(milliseconds: 300),
  126. padding: const EdgeInsets.only(
  127. top: 5,
  128. bottom: 5,
  129. left: 15,
  130. ),
  131. decoration: BoxDecoration(
  132. borderRadius: const BorderRadius.only(
  133. topLeft: Radius.circular(4),
  134. bottomLeft: Radius.circular(4),
  135. ),
  136. color: Colors.grey.withOpacity(0.6),
  137. ),
  138. width: _width,
  139. height: 60,
  140. child: _isExpanded
  141. ? FutureBuilder(
  142. future: _showList(),
  143. builder: (context, snapshot) {
  144. if (!snapshot.hasData) {
  145. return const SizedBox();
  146. }
  147. return Row(
  148. children: buildTitleButtonList(),
  149. );
  150. },
  151. )
  152. : const SizedBox(),
  153. ),
  154. ),
  155. InkWell(
  156. onTap: () {},
  157. onHover: (isHover) {
  158. if (isHover) {
  159. setState(() {
  160. _width = buildTitleButtonList().length * 48;
  161. _isExpanded = isHover;
  162. });
  163. } else {
  164. setState(() {
  165. _width = 0;
  166. _isExpanded = isHover;
  167. });
  168. }
  169. },
  170. child: Container(
  171. height: 60,
  172. color: Colors.white,
  173. child: !_isExpanded
  174. ? const Icon(Icons.chevron_left_rounded)
  175. : const Icon(Icons.chevron_right_rounded),
  176. ),
  177. ),
  178. ],
  179. );
  180. }
  181. FWidget _buildShareQr(String itemCurrentImage) {
  182. return FSimpleDialog(
  183. title: FText(
  184. i18nBook.remedical.share.t,
  185. style: const TextStyle(
  186. color: Colors.white,
  187. fontSize: 18,
  188. ),
  189. ),
  190. isDefault: false,
  191. children: [
  192. FContainer(
  193. width: 360,
  194. child: FContainer(
  195. padding: const EdgeInsets.only(top: 20, bottom: 20),
  196. child: QRCodeWithLogo(
  197. itemCurrentImage,
  198. codeStatement: i18nBook.remedical.scanQrCodeToShareImage.t,
  199. operationStatement: i18nBook.remedical.copyLink.t,
  200. operationSuccessCallback: () =>
  201. {PromptBox.toast(i18nBook.remedical.copySuccess.t)},
  202. ),
  203. ),
  204. ),
  205. ],
  206. );
  207. }
  208. //定义方法
  209. void _launchURL(url) async {
  210. if (await canLaunch(url)) {
  211. await launch(url);
  212. } else {
  213. throw 'Could not launch $url';
  214. }
  215. }
  216. //跳转
  217. Future<bool> _showList() async {
  218. await Future.delayed(const Duration(milliseconds: 300));
  219. return true;
  220. }
  221. Widget _buildTitleButton(IconData icon, String title, Function onClick) {
  222. return Container(
  223. margin: const EdgeInsets.only(
  224. right: 10,
  225. ),
  226. child: InkWell(
  227. onTap: () => onClick.call(),
  228. child: Column(
  229. children: [
  230. Icon(
  231. icon,
  232. color: Colors.white,
  233. ),
  234. Text(
  235. title,
  236. style: const TextStyle(
  237. color: Colors.white,
  238. fontSize: 14,
  239. ),
  240. )
  241. ],
  242. ),
  243. ),
  244. );
  245. }
  246. }