Эх сурвалжийг харах

update(ui): 尝试修正截图保存控件未隐藏的问题 #0009572 Review by baka

gavin.chen 2 жил өмнө
parent
commit
645ba8aed3

+ 20 - 19
lib/view/measure/measure_main_view.dart

@@ -31,6 +31,7 @@ import 'package:fis_measure/view/result/results_panel.dart';
 import 'package:fis_measure/view/standard_line/calibration_canvas.dart';
 import 'package:fis_measure/view/standard_line/calibration_gesture.dart';
 import 'package:fis_ui/index.dart';
+import 'package:fis_ui/widgets/layout/offstage.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter/rendering.dart';
 import 'package:get/get.dart';
@@ -88,7 +89,7 @@ class _MeasureMainViewState extends State<MeasureMainView> {
   IStandardLineCalibrationController? standardLineCalibrationController;
 
   final playerKey = GlobalKey();
-  final _key = GlobalKey();
+  final _captureAreaKey = GlobalKey();
 
   bool get inAnnotation =>
       application.currentOperateType == MeasureOperateType.annotation;
@@ -219,9 +220,9 @@ class _MeasureMainViewState extends State<MeasureMainView> {
 
   /// 保存图片
   void capturePng() async {
-    isCaptureState = true;
-    setState(() {});
-
+    setState(() {
+      isCaptureState = true;
+    });
     final features = <IMeasureItemFeature>[];
     for (var item in application.measureItems) {
       if (item.measuredFeatures.isNotEmpty) {
@@ -235,16 +236,14 @@ class _MeasureMainViewState extends State<MeasureMainView> {
       measureApplicationName: application.applicationName,
       features: features,
     );
-    //加延时是为了等待UI消失,防止截图截到UI
-    await Future.delayed(const Duration(milliseconds: 10), () async {
-      final RenderRepaintBoundary? boundary =
-          _key.currentContext?.findRenderObject() as RenderRepaintBoundary?;
-
+    //加延时是为了等待 UI 消失,防止截图截到 UI
+    Future.delayed(const Duration(milliseconds: 100), () async {
+      final RenderRepaintBoundary? boundary = _captureAreaKey.currentContext
+          ?.findRenderObject() as RenderRepaintBoundary?;
       if (boundary != null) {
         final image = await boundary.toImage();
         final byteData = await image.toByteData(format: ImageByteFormat.png);
         final pngBytes = byteData!.buffer.asUint8List();
-        isCaptureState = false;
         PromptBox.snackbar(
             i18nBook.measure.saveLocation.t +
                 ' > ' +
@@ -253,7 +252,9 @@ class _MeasureMainViewState extends State<MeasureMainView> {
             title: i18nBook.measure.screenshotSuccessfully.t,
             textColor: Colors.white,
             backgroundColor: Colors.black.withOpacity(0.7));
-        setState(() {});
+        setState(() {
+          isCaptureState = false;
+        });
         measureData.saveImage.call(
           pngBytes,
           measureData.measureImageData.patientCode ?? '',
@@ -380,7 +381,7 @@ class _MeasureMainViewState extends State<MeasureMainView> {
                 children: [
                   Expanded(
                     child: RepaintBoundary(
-                      key: _key,
+                      key: _captureAreaKey,
                       child: CustomMultiChildLayout(
                         delegate: _LayerLayoutDelegate(),
                         children: [
@@ -421,13 +422,15 @@ class _MeasureMainViewState extends State<MeasureMainView> {
                               id: _LayerLayoutIds.result,
                               child: const MeasureResultPanel(),
                             ),
-                            if (!isCaptureState)
-                              LayoutId(
-                                id: _LayerLayoutIds.buttonGroups,
+                            LayoutId(
+                              id: _LayerLayoutIds.buttonGroups,
+                              child: FOffstage(
+                                offstage: isCaptureState,
                                 child: FButtonGroup(
                                   capturePng: () => capturePng(),
                                 ),
-                              )
+                              ),
+                            )
                           ],
                           if (canShowAI) ...[
                             LayoutId(
@@ -560,7 +563,7 @@ class _LayerLayoutDelegate extends MultiChildLayoutDelegate {
     final offset = layoutOffset!;
     final renderSize = layoutSize!;
     final rightSpace = (size.width - renderSize.width) / 2;
-    // 如果图像右侧剩余可用空间大于60,则将按钮组放在右侧,如果小于60,则尽可能靠右
+    // 如果图像右侧剩余可用空间大于60,则将按钮组放在右侧,如果小于60,则尽可能靠右,60是按钮组宽度
     final buttonGroupOffsetX = min(rightSpace, 60.0);
 
     /// 同步图像显示尺寸
@@ -568,7 +571,6 @@ class _LayerLayoutDelegate extends MultiChildLayoutDelegate {
 
     layoutLayer(_LayerLayoutIds.player, offset, renderSize);
     layoutLayer(_LayerLayoutIds.loadingTipsOverlay, offset, renderSize);
-    // layoutLayer(_LayerLayoutIds.playerLoadding, offset, renderSize);
 
     /// 其他层按播放器尺寸位置层叠布局
     layoutLayer(_LayerLayoutIds.recordsCanvas, offset, renderSize);
@@ -584,7 +586,6 @@ class _LayerLayoutDelegate extends MultiChildLayoutDelegate {
     layoutLayer(_LayerLayoutIds.pause, offset, renderSize);
     layoutLayer(_LayerLayoutIds.paintAI, offset, renderSize);
     layoutLayer(_LayerLayoutIds.aiTips, Offset(0.0, size.height), renderSize);
-    // 60是按钮组宽度
     layoutLayer(_LayerLayoutIds.buttonGroups,
         offset.translate(buttonGroupOffsetX, 0), renderSize);
   }