1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- import 'package:fis_measure/interfaces/process/items/item_feature.dart';
- import 'package:fis_measure/interfaces/process/workspace/application.dart';
- import 'package:flutter/material.dart';
- import 'package:get/get.dart';
- class MeasureActiveCanvasPanel extends StatefulWidget {
- const MeasureActiveCanvasPanel({Key? key}) : super(key: key);
- @override
- State<StatefulWidget> createState() => _ActiveCanvasPanelState();
- }
- class _ActiveCanvasPanelState extends State<MeasureActiveCanvasPanel> {
- late final application = Get.find<IApplication>();
- IMeasureItemFeature? feature;
- @override
- void initState() {
- feature = application.activeMeasureItem?.feature;
- _addListenrs();
- super.initState();
- }
- @override
- void dispose() {
- _removeListenrs();
- super.dispose();
- }
- @override
- Widget build(BuildContext context) {
- if (feature == null) return const SizedBox();
- return LayoutBuilder(builder: (context, constraints) {
- return ClipRect(
- child: SizedBox(
- width: constraints.maxWidth,
- height: constraints.maxHeight,
- child: RepaintBoundary(
- child: CustomPaint(
- painter: _PanelPainter(feature!),
- ),
- ),
- ),
- );
- });
- }
- void _onMeasureRerenderReady(Object sender, void e) {
- if (mounted) {
- setState(() {
- feature = application.activeMeasureItem?.feature;
- });
- }
- }
- void _addListenrs() {
- application.updateRenderReady.addListener(_onMeasureRerenderReady);
- }
- void _removeListenrs() {
- application.updateRenderReady.removeListener(_onMeasureRerenderReady);
- }
- }
- class _PanelPainter extends CustomPainter {
- final IMeasureItemFeature feature;
- _PanelPainter(this.feature);
- @override
- void paint(Canvas canvas, Size size) {
- if (feature.checkCanPaint()) {
- feature.paint(canvas, size);
- }
- }
- @override
- bool shouldRepaint(covariant _PanelPainter oldDelegate) {
- return oldDelegate.hashCode != hashCode;
- }
- }
|