measure_left_annotation.dart 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import 'package:fis_measure/interfaces/enums/annotation.dart';
  2. import 'package:fis_measure/interfaces/process/workspace/application.dart';
  3. import 'package:fis_measure/process/workspace/measure_data_controller.dart';
  4. import 'package:fis_measure/process/workspace/measure_handler.dart';
  5. import 'package:fis_ui/index.dart';
  6. import 'package:flutter/material.dart';
  7. import 'package:get/get.dart';
  8. /// 注释项
  9. ///
  10. // ignore: must_be_immutable
  11. class MeasureLeftAnnotation extends StatefulWidget implements FWidget {
  12. const MeasureLeftAnnotation({Key? key}) : super(key: key);
  13. @override
  14. State<StatefulWidget> createState() => _MeasureLeftAnnotationState();
  15. }
  16. class _MeasureLeftAnnotationState extends State<MeasureLeftAnnotation> {
  17. // ignore: non_constant_identifier_names
  18. // static final C_SUPPORTED_TEXTS = measureData.annotationList;
  19. final scrollController = ScrollController();
  20. final application = Get.find<IApplication>();
  21. late final measureHandler = Get.find<MeasureHandler>();
  22. /// 数据
  23. late final measureData = Get.find<MeasureDataController>();
  24. void annotationListChanged(sender, e) {
  25. setState(() {});
  26. }
  27. @override
  28. void initState() {
  29. measureData.annotationListChanged.addListener(annotationListChanged);
  30. super.initState();
  31. }
  32. @override
  33. void dispose() {
  34. measureData.annotationListChanged.removeListener(annotationListChanged);
  35. super.dispose();
  36. }
  37. @override
  38. Widget build(BuildContext context) {
  39. return SizedBox(
  40. width: 300,
  41. child: Scrollbar(
  42. controller: scrollController,
  43. thumbVisibility: true,
  44. child: GridView.count(
  45. controller: scrollController,
  46. crossAxisCount: 2,
  47. childAspectRatio: 3,
  48. children: measureData.annotationList.map((e) {
  49. return _buildAnnotationTools(e);
  50. }).toList(),
  51. ),
  52. ),
  53. );
  54. }
  55. Widget _buildAnnotationTools(String tools) {
  56. const style = TextStyle(color: Colors.white, fontSize: 14);
  57. const dragStyle = TextStyle(color: Colors.amber, fontSize: 18);
  58. return Row(
  59. mainAxisSize: MainAxisSize.max,
  60. children: [
  61. const FSizedBox(
  62. width: 12,
  63. ),
  64. Expanded(
  65. child: Draggable<String>(
  66. data: tools,
  67. dragAnchorStrategy: (data, context, offset) {
  68. return Offset.zero;
  69. },
  70. child: OutlinedButton(
  71. child: Text(tools, style: style),
  72. onPressed: () {
  73. measureHandler.changedAnnotationType = AnnotationType.label;
  74. application.switchAnnotation(AnnotationType.label, tools);
  75. },
  76. style: OutlinedButton.styleFrom(
  77. shape: RoundedRectangleBorder(
  78. borderRadius: BorderRadius.circular(4),
  79. ),
  80. side: const BorderSide(
  81. color: Color.fromRGBO(124, 124, 124, 1),
  82. ),
  83. fixedSize: const Size.fromHeight(40),
  84. ),
  85. ),
  86. feedback: Material(
  87. color: Colors.transparent,
  88. child: Text(tools, style: dragStyle),
  89. ),
  90. onDragStarted: () {
  91. measureHandler.changedAnnotationType = AnnotationType.label;
  92. measureHandler.onDragStateChanged.emit(this, true);
  93. application.switchAnnotation(AnnotationType.label, tools);
  94. },
  95. onDragEnd: (details) {
  96. measureHandler.onDragStateChanged.emit(this, false);
  97. },
  98. onDragCompleted: () {
  99. measureHandler.onDragStateChanged.emit(this, false);
  100. },
  101. onDraggableCanceled: (velocity, offset) {
  102. measureHandler.onDragStateChanged.emit(this, false);
  103. },
  104. ),
  105. ),
  106. const FSizedBox(
  107. width: 12,
  108. ),
  109. ],
  110. );
  111. }
  112. }