浏览代码

修复编辑报告中选择词条内容较多时无法动态增加输入框的高度

loki.wu 2 年之前
父节点
当前提交
21cfc1f38a
共有 3 个文件被更改,包括 48 次插入24 次删除
  1. 2 2
      assets/test.json
  2. 43 20
      lib/pages/components/input_text.dart
  3. 3 2
      lib/report_info/input_text_info.dart

+ 2 - 2
assets/test.json

@@ -32,11 +32,11 @@
     },
     {
         "Key": "9dbbaa61-a91d-4399-a3f4-df29117d2d59",
-        "Value": "图1 肝脏大小形态正常,包膜光整,实质回声密集增强。内另见一个高回声区,大小约 1.34cm x\r\n     0.91cm ,边界清,内部回声均匀。\r\n图2 内见一个强回声区,大小约 0.69cm x 0.38cm ,后方有声影。余肝实质回声均匀。"
+        "Value": "2.肝血图改变 \r\n   图1 2.肝血图改变 \r\n   图1 2.肝血图改变 \r\n   图1 2.肝血图改变 \r\n   图1 2.肝血图改变 \r\n   图1 2.肝血图改变 \r\n   图1 2.肝血图改变 \r\n   图1 2.肝血图改变 \r\n   图1 肝脏大小形态正常,包膜光整,实质回声密集增强。内另见一个高回声区,大小约 1.34cm x\r\n     0.91cm ,边界清,内部回声均匀。\r\n图2 内见一个强回声区,大小约 0.69cm x 0.38cm ,后方有声影。余肝实质回声均匀。"
     },
     {
         "Key": "9ebbaa61-a91d-4399-a3f4-df29117d2d59",
-        "Value": "图1 1.符合脂肪肝声像图改变 \r\n    2.肝血管瘤\r\n图2 肝内强回声灶"
+        "Value": "图改变 \r\n    2.肝血图改变 \r\n    2.肝血图改变 \r\n    2.肝血图改变 \r\n    2.肝血图1 1.符合脂肪肝声像图改变 \r\n    2.肝血管瘤\r\n图2 肝内强回声灶"
     },
     {
         "Key": "7abbaa61-a91d-4399-a3f4-df29117d2d59",

+ 43 - 20
lib/pages/components/input_text.dart

@@ -26,32 +26,32 @@ class _RInputTextState extends State<RInputText> {
   double _lineWidth = 136.0;
   double _fontSize = 22.0;
   double _height = 22.0;
-  bool? _textWrap = false;
+  double _allHeight = 0.0;
+  bool _textWrap = false;
   Color _fontColor = const Color.fromARGB(255, 0, 0, 0);
   Color _backgroundColor = const Color.fromARGB(255, 255, 255, 255);
-  int? _lineLength = 1;
+  int _lineLength = 1;
   TextStyle? _textStyle;
   InputTextInfo? _inputTextInfo;
   bool _isReadOnly = false;
-  String _text = '';
+  bool _widthLock = false;
+  int _rowCount = 1;
 
   @override
   initState() {
-    ReportInfo.instance.onReloadFinsh.addListener((sender, e) {
-      _initDatas();
-    });
     super.initState();
   }
 
   @override
   Widget build(BuildContext context) {
-    _syncStyle();
     _checkInputTextInfo();
+    _initStyle();
+
     return Column(
       children: [
         Container(
           width: _lineWidth,
-          height: _textWrap! ? _height * 4 : (_height - 2),
+          height: _allHeight,
           padding: const EdgeInsets.only(right: 5, left: 5),
           decoration: BoxDecoration(
             border: Border.all(
@@ -67,18 +67,18 @@ class _RInputTextState extends State<RInputText> {
               textAlignVertical: AlignmentConvert.verticalAlignmentConvert(
                   widget.inputText.verticalAlignment),
               minLines: 1,
-              maxLines: _textWrap! ? 6 : 1,
+              maxLines: _rowCount,
               controller: _controller,
               textAlign: TextAlign.start,
               style: _textStyle,
               onChanged: (v) {
-                //  _onInputChanged(_textStyle!, v);
+                // _onInputChanged(_textStyle!, _controller.text);
               },
               onEditingComplete: () {
                 _onInputChanged(_textStyle!, _controller.text);
               }),
         ),
-        const SizedBox(height: 5),
+        const SizedBox(height: 3),
         if (_inputTextInfo!.tag != null &&
             _inputTextInfo!.tag!.elementTagType ==
                 ElementTagType.DiagnosticEntry) ...[
@@ -111,12 +111,9 @@ class _RInputTextState extends State<RInputText> {
 
   //onchange 事件
   void _onInputChanged(TextStyle _textStyle, String value) {
-    final inputText = widget.inputText;
     if (_inputTextInfo != null) {
       _inputTextInfo!.text = value;
     }
-
-    _syncWidth(inputText, value);
   }
 
   @override
@@ -177,12 +174,14 @@ class _RInputTextState extends State<RInputText> {
         setState(() {
           if (width < 480) {
             _lineWidth = width;
+            _widthLock = true;
           }
         });
       } else if (_controller.text.isEmpty) {
         setState(() {
           //重置长度
-          _lineWidth = inputText.lineWidth ?? 100;
+          _lineWidth = PtToPxConverter.ptToPx(inputText.lineWidth);
+          _widthLock = false;
         });
       } else if (TextSizeConvert.getTextSize(_controller.text, _textStyle!)
               .width >
@@ -190,14 +189,14 @@ class _RInputTextState extends State<RInputText> {
         setState(() {
           if (width < 480) {
             _lineWidth = width;
+            _widthLock = true;
           }
         });
       }
-      inputText.lineWidth = _lineWidth;
     }
   }
 
-  void _syncStyle() {
+  void _initStyle() {
     final inputText = widget.inputText;
     _textStyle ??= TextStyle(
       fontSize: PtToPxConverter.ptToPx(inputText.fontSize),
@@ -208,11 +207,35 @@ class _RInputTextState extends State<RInputText> {
     final fontName = inputText.fontName;
     //TODO(Loki):常规模板暂未设置fontStyles,后续再支持
     final fontStyles = inputText.fontStyles;
-    _lineLength = inputText.lineLength;
-    _lineWidth = PtToPxConverter.ptToPx(inputText.lineWidth);
-    _textWrap = inputText.textWrap;
+    _lineLength = inputText.lineLength ?? 7;
+    if (!_widthLock) {
+      _lineWidth = PtToPxConverter.ptToPx(inputText.lineWidth);
+    }
+    _widthLock = false;
+    _textWrap = inputText.textWrap ?? false;
+    _rowCount = _textWrap ? 6 : 1;
+
+    if (_inputTextInfo != null && _inputTextInfo!.text.isNotEmpty) {
+      final text = _inputTextInfo!.text;
+      if (text.contains('\r\n')) {
+        final rowList = text.split('\r\n');
+        _rowCount = rowList.length > _rowCount ? rowList.length : _rowCount;
+      }
+    }
     _fontSize = PtToPxConverter.ptToPx(inputText.fontSize);
     _height = _fontSize > 30 ? 44 : 22;
+    _allHeight = _textWrap
+        ? _height * (_rowCount - 1)
+        : _fontSize > 30
+            ? (_height - 2)
+            : _height;
+    if (_inputTextInfo != null && _textWrap) {
+      final height =
+          TextSizeConvert.getTextSize(_controller.text, _textStyle!).height + 5;
+      if (height > _allHeight) {
+        _allHeight = height;
+      }
+    }
   }
 
   void _checkInputTextInfo() {

+ 3 - 2
lib/report_info/input_text_info.dart

@@ -1,5 +1,3 @@
-import 'dart:convert';
-
 import 'package:fis_lib_report/converts/event_type.dart';
 import 'package:fis_lib_report/report/inputText.dart';
 import 'package:fis_lib_report/report_info/report_info.dart';
@@ -9,6 +7,9 @@ class InputTextInfo extends TextElementInfo {
   ///是否只读
   bool? isReadOnly;
 
+  ///输入框宽度
+  double lineWidth = 0.0;
+
   ///当前输入框是否已经监听
   bool? isListening;