label_drag_target_pannel.dart 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import 'package:fis_measure/interfaces/process/workspace/application.dart';
  2. import 'package:fis_measure/interfaces/process/workspace/point_info.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:get/get.dart';
  5. import '../positioned_cursor.dart';
  6. /// 文本注释拖拽目标面板
  7. class AnnotationLabelDragTargetPanel extends StatefulWidget {
  8. const AnnotationLabelDragTargetPanel({Key? key}) : super(key: key);
  9. @override
  10. State<StatefulWidget> createState() => _PanelState();
  11. }
  12. class _PanelState extends State<AnnotationLabelDragTargetPanel> {
  13. late final application = Get.find<IApplication>();
  14. @override
  15. void initState() {
  16. // TODO: implement initState
  17. super.initState();
  18. }
  19. @override
  20. Widget build(BuildContext context) {
  21. return Container(
  22. // color: Colors.green,
  23. child: DragTarget<String>(
  24. builder: (context, candidateData, rejectedData) {
  25. return Container(
  26. child: Stack(
  27. children: const [
  28. PositionedCursor(),
  29. ],
  30. ),
  31. );
  32. },
  33. onMove: (details) {
  34. _notifyPosition(context, details.offset, PointInfoType.mouseMove);
  35. },
  36. onAcceptWithDetails: (details) {
  37. _notifyPosition(context, details.offset, PointInfoType.mouseUp);
  38. },
  39. ),
  40. );
  41. }
  42. void _notifyPosition(
  43. BuildContext context,
  44. Offset offset,
  45. PointInfoType type,
  46. ) {
  47. final localOffset = _findLocalPosition(context, offset);
  48. application.createPointInfo(localOffset, type);
  49. }
  50. Offset _findLocalPosition(BuildContext context, Offset globalPosition) {
  51. final renderBox = context.findRenderObject() as RenderBox?;
  52. if (renderBox == null) return globalPosition;
  53. return renderBox.globalToLocal(globalPosition);
  54. }
  55. @override
  56. void dispose() {
  57. // TODO: implement dispose
  58. super.dispose();
  59. }
  60. }