mobile_annotation_gesture.dart 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. IAnnotationItem? currentItem;
  18. @override
  19. void initState() {
  20. currentItem = application.activeAnnotationItem;
  21. application.activeAnnotationItemChanged.addListener(_onItemChanged);
  22. super.initState();
  23. }
  24. @override
  25. void dispose() {
  26. application.activeAnnotationItemChanged.removeListener(_onItemChanged);
  27. super.dispose();
  28. }
  29. void _onItemChanged(Object sender, IAnnotationItem? item) {
  30. if (!mounted) return;
  31. if (item?.type != currentItem?.type) {
  32. setState(() {
  33. currentItem = item;
  34. });
  35. } else {
  36. currentItem = item;
  37. }
  38. }
  39. @override
  40. Widget build(BuildContext context) {
  41. return _buildItemPanel();
  42. }
  43. Widget _buildItemPanel() {
  44. if (currentItem == null) {
  45. return const SizedBox();
  46. }
  47. final type = currentItem!.type;
  48. switch (type) {
  49. case AnnotationType.label:
  50. return const AnnotationLabelDragTargetPanel();
  51. case AnnotationType.input:
  52. return Container();
  53. case AnnotationType.arrow:
  54. return const AnnotationArrowGesturePanel();
  55. }
  56. }
  57. }