import 'package:fis_measure/interfaces/enums/annotation.dart'; import 'package:fis_measure/interfaces/process/workspace/application.dart'; import 'package:fis_measure/process/workspace/measure_data_controller.dart'; import 'package:fis_measure/process/workspace/measure_handler.dart'; import 'package:fis_ui/index.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; /// 注释项 /// // ignore: must_be_immutable class MeasureLeftAnnotation extends StatefulWidget implements FWidget { const MeasureLeftAnnotation({Key? key}) : super(key: key); @override State createState() => _MeasureLeftAnnotationState(); } class _MeasureLeftAnnotationState extends State { // ignore: non_constant_identifier_names // static final C_SUPPORTED_TEXTS = measureData.annotationList; final scrollController = ScrollController(); final application = Get.find(); late final measureHandler = Get.find(); /// 数据 late final measureData = Get.find(); void annotationListChanged(sender, e) { setState(() {}); } @override void initState() { measureData.annotationListChanged.addListener(annotationListChanged); super.initState(); } @override void dispose() { measureData.annotationListChanged.removeListener(annotationListChanged); super.dispose(); } @override Widget build(BuildContext context) { return SizedBox( width: 300, child: Scrollbar( controller: scrollController, thumbVisibility: true, child: GridView.count( controller: scrollController, crossAxisCount: 2, childAspectRatio: 3, children: measureData.annotationList.map((e) { return _buildAnnotationTools(e); }).toList(), ), ), ); } Widget _buildAnnotationTools(String tools) { const style = TextStyle(color: Colors.white, fontSize: 14); const dragStyle = TextStyle(color: Colors.amber, fontSize: 18); return Row( mainAxisSize: MainAxisSize.max, children: [ const FSizedBox( width: 12, ), Expanded( child: Draggable( data: tools, dragAnchorStrategy: (data, context, offset) { return Offset.zero; }, child: OutlinedButton( child: Text(tools, style: style), onPressed: () { measureHandler.changedAnnotationType = AnnotationType.label; application.switchAnnotation(AnnotationType.label, tools); }, style: OutlinedButton.styleFrom( shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(4), ), side: const BorderSide( color: Color.fromRGBO(124, 124, 124, 1), ), fixedSize: const Size.fromHeight(40), ), ), feedback: Material( color: Colors.transparent, child: Text(tools, style: dragStyle), ), onDragStarted: () { measureHandler.changedAnnotationType = AnnotationType.label; measureHandler.onDragStateChanged.emit(this, true); application.switchAnnotation(AnnotationType.label, tools); }, onDragEnd: (details) { measureHandler.onDragStateChanged.emit(this, false); }, onDragCompleted: () { measureHandler.onDragStateChanged.emit(this, false); }, onDraggableCanceled: (velocity, offset) { measureHandler.onDragStateChanged.emit(this, false); }, ), ), const FSizedBox( width: 12, ), ], ); } }