mobile_annotation_gesture.dart 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 'label_drag_target_pannel.dart';
  9. /// 移动端注释手势层
  10. class AnnotationTouchLayer extends StatefulWidget {
  11. const AnnotationTouchLayer({Key? key}) : super(key: key);
  12. @override
  13. State<AnnotationTouchLayer> createState() => _AnnotationTouchLayerState();
  14. }
  15. class _AnnotationTouchLayerState extends State<AnnotationTouchLayer> {
  16. late final application = Get.find<IApplication>();
  17. final mouseState = Get.put<IMouseState>(MouseState());
  18. IAnnotationItem? currentItem;
  19. @override
  20. void initState() {
  21. currentItem = application.activeAnnotationItem;
  22. application.activeAnnotationItemChanged.addListener(_onItemChanged);
  23. super.initState();
  24. }
  25. @override
  26. void dispose() {
  27. application.activeAnnotationItemChanged.removeListener(_onItemChanged);
  28. super.dispose();
  29. }
  30. void _onItemChanged(Object sender, IAnnotationItem? item) {
  31. if (!mounted) return;
  32. if (item?.type != currentItem?.type) {
  33. setState(() {
  34. currentItem = item;
  35. });
  36. } else {
  37. currentItem = item;
  38. }
  39. }
  40. @override
  41. Widget build(BuildContext context) {
  42. return _buildItemPanel();
  43. }
  44. Widget _buildItemPanel() {
  45. if (currentItem == null) {
  46. return const SizedBox();
  47. }
  48. final type = currentItem!.type;
  49. switch (type) {
  50. case AnnotationType.label:
  51. return const AnnotationLabelDragTargetPanel();
  52. case AnnotationType.input:
  53. return Container();
  54. case AnnotationType.arrow:
  55. return const AnnotationArrowGesturePanel();
  56. }
  57. }
  58. }