import 'package:fis_measure/interfaces/enums/annotation.dart'; import 'package:fis_measure/interfaces/process/annotations/annotation.dart'; import 'package:fis_measure/interfaces/process/workspace/application.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import '../positioned_cursor.dart'; import 'arrow_gesture_panel.dart'; import 'input_position_panel.dart'; import 'label_drag_target_pannel.dart'; /// 移动端注释手势层 class AnnotationTouchLayer extends StatefulWidget { const AnnotationTouchLayer({Key? key}) : super(key: key); @override State createState() => _AnnotationTouchLayerState(); } class _AnnotationTouchLayerState extends State { late final application = Get.find(); final mouseState = Get.put(MouseState()); IAnnotationItem? currentItem; @override void initState() { currentItem = application.activeAnnotationItem; application.activeAnnotationItemChanged.addListener(_onItemChanged); super.initState(); } @override void dispose() { application.activeAnnotationItemChanged.removeListener(_onItemChanged); super.dispose(); } void _onItemChanged(Object sender, IAnnotationItem? item) { if (!mounted) return; if (item?.type != currentItem?.type) { setState(() { currentItem = item; }); } else { currentItem = item; } } @override Widget build(BuildContext context) { return _buildItemPanel(); // // TODO: melon - optimize with handlers // return Stack( // children: [ // _buildItemPanel(), // _buildTopGesture(), // ], // ); } // Widget _buildTopGesture() { // return GestureDetector( // onPanUpdate: (details) { // mouseState.mousePosition = details.localPosition; // }, // child: MouseRegion( // cursor: SystemMouseCursors.none, // onHover: (details) { // mouseState.mousePosition = details.localPosition; // }, // child: Stack( // children: const [ // PositionedCursor(), // ], // ), // ), // ); // } Widget _buildItemPanel() { if (currentItem == null) { return const SizedBox(); } final type = currentItem!.type; switch (type) { case AnnotationType.label: return const AnnotationLabelDragTargetPanel(); case AnnotationType.input: return const AnnotationInputPositionPanel(); case AnnotationType.arrow: return const AnnotationArrowGesturePanel(); } } }