measure_area_indicator.dart 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import 'package:fis_measure/interfaces/process/visuals/visual_area.dart';
  2. import 'package:fis_measure/interfaces/process/workspace/application.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:get/get.dart';
  5. import 'package:vid/us/vid_us_visual_area_type.dart';
  6. class MeasureAreaIndicator extends StatefulWidget {
  7. const MeasureAreaIndicator({super.key});
  8. @override
  9. State<MeasureAreaIndicator> createState() => _MeasureAreaIndicatorState();
  10. }
  11. class _MeasureAreaIndicatorState extends State<MeasureAreaIndicator> {
  12. late IApplication application = Get.find<IApplication>();
  13. /// 高度百分比
  14. double regionHeight = 0;
  15. /// 宽度百分比
  16. double regionWidth = 0;
  17. /// Top百分比
  18. double regionTop = 0;
  19. /// Left百分比
  20. double regionLeft = 0;
  21. @override
  22. void initState() {
  23. super.initState();
  24. application.visualAreaChanged.addListener(_visualAreaChanged);
  25. _initVisualArea(application.currentVisualArea);
  26. }
  27. @override
  28. void dispose() {
  29. super.dispose();
  30. application.visualAreaChanged.removeListener(_visualAreaChanged);
  31. }
  32. void _visualAreaChanged(sender, IVisualArea e) {
  33. if (mounted) {
  34. _setMeasureArea(e);
  35. }
  36. }
  37. void _setMeasureArea(IVisualArea e) {
  38. if (e.visualAreaType == VidUsVisualAreaType.TissueTimeMotion ||
  39. e.visualAreaType == VidUsVisualAreaType.Doppler) {
  40. regionHeight = (1 - e.displayRegion.top) * context.size!.height;
  41. regionWidth = context.size!.width;
  42. regionTop = e.displayRegion.top * context.size!.height;
  43. regionLeft = 0;
  44. } else {
  45. regionHeight = e.displayRegion.height * context.size!.height;
  46. regionWidth = e.displayRegion.width * context.size!.width;
  47. regionTop = e.displayRegion.top * context.size!.height;
  48. regionLeft = e.displayRegion.left * context.size!.width;
  49. }
  50. setState(() {});
  51. }
  52. void _initVisualArea(IVisualArea e) {
  53. WidgetsBinding.instance.addPostFrameCallback((_) {
  54. _setMeasureArea(e);
  55. });
  56. }
  57. @override
  58. Widget build(BuildContext context) {
  59. return IgnorePointer(
  60. child: Stack(
  61. children: [
  62. Positioned(
  63. top: regionTop,
  64. left: regionLeft,
  65. child: Container(
  66. width: regionWidth,
  67. height: regionHeight,
  68. decoration: BoxDecoration(
  69. border: Border.all(
  70. strokeAlign: BorderSide.strokeAlignCenter,
  71. color: Colors.grey.withOpacity(0.5),
  72. width: 1,
  73. ),
  74. ),
  75. ),
  76. ),
  77. ],
  78. ),
  79. );
  80. }
  81. }