12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- 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';
- class AnnotationCanvas extends StatefulWidget {
- const AnnotationCanvas({Key? key}) : super(key: key);
- @override
- State<StatefulWidget> createState() => _AnnotationCanvasState();
- }
- class _AnnotationCanvasState extends State<AnnotationCanvas> {
- late final application = Get.find<IApplication>();
- IAnnotationItemFeature? feature;
- @override
- void initState() {
- feature = application.activeAnnotationItem?.feature;
- application.updateRenderReady.addListener(_onUpdateRenderReady);
- super.initState();
- }
- @override
- void dispose() {
- application.updateRenderReady.removeListener(_onUpdateRenderReady);
- super.dispose();
- }
- @override
- Widget build(BuildContext context) {
- final feature = application.activeAnnotationItem?.feature;
- if (feature == null) return const SizedBox();
- return LayoutBuilder(builder: (context, constraints) {
- return SizedBox(
- width: constraints.maxWidth,
- height: constraints.maxHeight,
- child: RepaintBoundary(
- child: CustomPaint(
- painter: _PanelPainter(feature),
- ),
- ),
- );
- });
- }
- void _onUpdateRenderReady(Object sender, void e) {
- if (mounted) {
- setState(() {
- feature = application.activeAnnotationItem?.feature;
- });
- }
- }
- }
- class _PanelPainter extends CustomPainter {
- final IAnnotationItemFeature feature;
- _PanelPainter(this.feature);
- @override
- void paint(Canvas canvas, Size size) {
- feature.paint(canvas, size);
- }
- @override
- bool shouldRepaint(covariant _PanelPainter oldDelegate) {
- return oldDelegate.hashCode != hashCode;
- }
- }
|