annotation_gesture.dart 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import 'package:fis_measure/interfaces/enums/annotation.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 '../positioned_cursor.dart';
  6. import 'arrow_gesture_panel.dart';
  7. import 'input_position_panel.dart';
  8. import 'label_drag_target_pannel.dart';
  9. /// 注释手势层
  10. class AnnotationGestureLayer extends StatefulWidget {
  11. const AnnotationGestureLayer({Key? key}) : super(key: key);
  12. @override
  13. State<AnnotationGestureLayer> createState() => _AnnotationGestureLayerState();
  14. }
  15. class _AnnotationGestureLayerState extends State<AnnotationGestureLayer> {
  16. late final application = Get.find<IApplication>();
  17. final mouseState = Get.put<IMouseState>(MouseState());
  18. @override
  19. Widget build(BuildContext context) {
  20. return _buildItemPanel();
  21. // TODO: melon - optimize with handlers
  22. return Stack(
  23. children: [
  24. _buildItemPanel(),
  25. _buildTopGesture(),
  26. ],
  27. );
  28. }
  29. Widget _buildTopGesture() {
  30. return GestureDetector(
  31. onPanUpdate: (details) {
  32. mouseState.mousePosition = details.localPosition;
  33. },
  34. child: MouseRegion(
  35. cursor: SystemMouseCursors.none,
  36. onHover: (details) {
  37. mouseState.mousePosition = details.localPosition;
  38. },
  39. child: Stack(
  40. children: const [
  41. PositionedCursor(),
  42. ],
  43. ),
  44. ),
  45. );
  46. }
  47. Widget _buildItemPanel() {
  48. final item = application.activeAnnotationItem;
  49. if (item == null) {
  50. return const SizedBox();
  51. }
  52. final type = item.type;
  53. switch (type) {
  54. case AnnotationType.label:
  55. return const AnnotationLabelDragTargetPanel();
  56. case AnnotationType.input:
  57. return const AnnotationInputPositionPanel();
  58. case AnnotationType.arrow:
  59. return const AnnotationArrowGesturePanel();
  60. }
  61. }
  62. }