|
@@ -1,8 +1,10 @@
|
|
|
import 'package:fis_lib_report/converts/pt_to_px_converter.dart';
|
|
|
import 'package:fis_lib_report/converts/vertical_alignment.dart';
|
|
|
import 'package:fis_lib_report/report/inputText.dart';
|
|
|
+import 'package:fis_lib_report/report/interfaces/position_layout.dart';
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
import 'package:flutter/material.dart';
|
|
|
+import 'package:flutter/rendering.dart';
|
|
|
|
|
|
class RInputText extends StatefulWidget {
|
|
|
final InputText inputText;
|
|
@@ -27,6 +29,7 @@ class _RInputTextState extends State<RInputText> {
|
|
|
Color _fontColor = const Color.fromARGB(255, 0, 0, 0);
|
|
|
Color _backgroundColor = const Color.fromARGB(255, 255, 255, 255);
|
|
|
int? _lineLength = 1;
|
|
|
+ TextStyle? _textStyle;
|
|
|
@override
|
|
|
initState() {
|
|
|
final fontColor = inputText.fontColor;
|
|
@@ -39,6 +42,10 @@ class _RInputTextState extends State<RInputText> {
|
|
|
_backgroundColor = Color.fromARGB(backgroundColor.a!, backgroundColor.r!,
|
|
|
backgroundColor.g!, backgroundColor.b!);
|
|
|
}
|
|
|
+ _textStyle = TextStyle(
|
|
|
+ fontSize: PtToPxConverter.ptToPx(inputText.fontSize),
|
|
|
+ color: _fontColor,
|
|
|
+ );
|
|
|
//TODO(Loki):set FontName in TextField
|
|
|
final fontName = inputText.fontName;
|
|
|
//TODO(Loki):常规模板暂未设置fontStyles,后续再支持
|
|
@@ -48,7 +55,6 @@ class _RInputTextState extends State<RInputText> {
|
|
|
_textWrap = inputText.textWrap;
|
|
|
_fontSize = PtToPxConverter.ptToPx(inputText.fontSize);
|
|
|
_height = _fontSize! > 30 ? 36.5 : 22;
|
|
|
-
|
|
|
print(_lineLength);
|
|
|
super.initState();
|
|
|
}
|
|
@@ -93,34 +99,16 @@ class _RInputTextState extends State<RInputText> {
|
|
|
textAlign: TextAlign.start,
|
|
|
style: _textStyle,
|
|
|
onChanged: (v) {
|
|
|
- if (_lineWidth! <
|
|
|
- boundingTextSize(_controller.text, _textStyle).width) {
|
|
|
- setState(() {
|
|
|
- if (_lineWidth! < 600) {
|
|
|
- _lineWidth = _lineWidth! + 12;
|
|
|
- }
|
|
|
- });
|
|
|
- } else if (_controller.text.isEmpty) {
|
|
|
- setState(() {
|
|
|
- _lineWidth = inputText.lineWidth;
|
|
|
- });
|
|
|
- } else if (boundingTextSize(_controller.text, _textStyle).width >
|
|
|
- inputText.lineWidth!) {
|
|
|
- setState(() {
|
|
|
- if (_lineWidth! < 600) {
|
|
|
- _lineWidth =
|
|
|
- boundingTextSize(_controller.text, _textStyle).width;
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
+ _onInputChanged(_textStyle, v);
|
|
|
},
|
|
|
),
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- static Size boundingTextSize(String text, TextStyle style,
|
|
|
+ ///计算文本Size
|
|
|
+ static Size _boundingTextSize(String text, TextStyle style,
|
|
|
{int maxLines = 2 ^ 31, double maxWidth = double.infinity}) {
|
|
|
- if (text == null || text.isEmpty) {
|
|
|
+ if (text.isEmpty) {
|
|
|
return Size.zero;
|
|
|
}
|
|
|
final TextPainter textPainter = TextPainter(
|
|
@@ -130,4 +118,32 @@ class _RInputTextState extends State<RInputText> {
|
|
|
..layout(maxWidth: maxWidth);
|
|
|
return textPainter.size;
|
|
|
}
|
|
|
+
|
|
|
+ //onchange 事件
|
|
|
+ void _onInputChanged(TextStyle _textStyle, String value) {
|
|
|
+ final width = _boundingTextSize(value, _textStyle).width;
|
|
|
+ // ignore: todo
|
|
|
+ //TODO(LOki):此处需要区分不同的输入框
|
|
|
+ if (inputText.tag!.name == 'HospitalName') {
|
|
|
+ if (_lineWidth! < width) {
|
|
|
+ setState(() {
|
|
|
+ if (width < 500) {
|
|
|
+ _lineWidth = width;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else if (_controller.text.isEmpty) {
|
|
|
+ setState(() {
|
|
|
+ //重置长度
|
|
|
+ _lineWidth = inputText.lineWidth;
|
|
|
+ });
|
|
|
+ } else if (_boundingTextSize(_controller.text, _textStyle).width >
|
|
|
+ inputText.lineWidth!) {
|
|
|
+ setState(() {
|
|
|
+ if (width < 500) {
|
|
|
+ _lineWidth = width;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|