mobile_annotation_gesture.dart 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import 'package:fis_measure/interfaces/enums/annotation.dart';
  2. import 'package:fis_measure/interfaces/process/annotations/annotation.dart';
  3. import 'package:fis_measure/interfaces/process/workspace/application.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:get/get.dart';
  6. import '../positioned_cursor.dart';
  7. import 'arrow_gesture_panel.dart';
  8. import 'input_position_panel.dart';
  9. import 'label_drag_target_pannel.dart';
  10. /// 移动端注释手势层
  11. class AnnotationTouchLayer extends StatefulWidget {
  12. const AnnotationTouchLayer({Key? key}) : super(key: key);
  13. @override
  14. State<AnnotationTouchLayer> createState() => _AnnotationTouchLayerState();
  15. }
  16. class _AnnotationTouchLayerState extends State<AnnotationTouchLayer> {
  17. late final application = Get.find<IApplication>();
  18. final mouseState = Get.put<IMouseState>(MouseState());
  19. IAnnotationItem? currentItem;
  20. @override
  21. void initState() {
  22. currentItem = application.activeAnnotationItem;
  23. application.activeAnnotationItemChanged.addListener(_onItemChanged);
  24. super.initState();
  25. }
  26. @override
  27. void dispose() {
  28. application.activeAnnotationItemChanged.removeListener(_onItemChanged);
  29. super.dispose();
  30. }
  31. void _onItemChanged(Object sender, IAnnotationItem? item) {
  32. if (!mounted) return;
  33. if (item?.type != currentItem?.type) {
  34. setState(() {
  35. currentItem = item;
  36. });
  37. } else {
  38. currentItem = item;
  39. }
  40. }
  41. @override
  42. Widget build(BuildContext context) {
  43. return _buildItemPanel();
  44. // // TODO: melon - optimize with handlers
  45. // return Stack(
  46. // children: [
  47. // _buildItemPanel(),
  48. // _buildTopGesture(),
  49. // ],
  50. // );
  51. }
  52. // Widget _buildTopGesture() {
  53. // return GestureDetector(
  54. // onPanUpdate: (details) {
  55. // mouseState.mousePosition = details.localPosition;
  56. // },
  57. // child: MouseRegion(
  58. // cursor: SystemMouseCursors.none,
  59. // onHover: (details) {
  60. // mouseState.mousePosition = details.localPosition;
  61. // },
  62. // child: Stack(
  63. // children: const [
  64. // PositionedCursor(),
  65. // ],
  66. // ),
  67. // ),
  68. // );
  69. // }
  70. Widget _buildItemPanel() {
  71. if (currentItem == null) {
  72. return const SizedBox();
  73. }
  74. final type = currentItem!.type;
  75. switch (type) {
  76. case AnnotationType.label:
  77. return const AnnotationLabelDragTargetPanel();
  78. case AnnotationType.input:
  79. return const AnnotationInputPositionPanel();
  80. case AnnotationType.arrow:
  81. return const AnnotationArrowGesturePanel();
  82. }
  83. }
  84. }