|
@@ -0,0 +1,133 @@
|
|
|
+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:flutter/cupertino.dart';
|
|
|
+import 'package:flutter/material.dart';
|
|
|
+
|
|
|
+class RInputText extends StatefulWidget {
|
|
|
+ final InputText inputText;
|
|
|
+
|
|
|
+ const RInputText({Key? key, required this.inputText}) : super(key: key);
|
|
|
+
|
|
|
+ @override
|
|
|
+ State<StatefulWidget> createState() {
|
|
|
+ return _RInputTextState(inputText: inputText);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+class _RInputTextState extends State<RInputText> {
|
|
|
+ _RInputTextState({required this.inputText});
|
|
|
+ final InputText inputText;
|
|
|
+ final _controller = TextEditingController(text: '');
|
|
|
+ final _focusNode = FocusNode();
|
|
|
+ double? _lineWidth = 136.0;
|
|
|
+ double? _fontSize = 22.0;
|
|
|
+ double? _height = 22.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;
|
|
|
+ @override
|
|
|
+ initState() {
|
|
|
+ final fontColor = inputText.fontColor;
|
|
|
+ if (fontColor != null) {
|
|
|
+ _fontColor = Color.fromARGB(
|
|
|
+ fontColor.a!, fontColor.r!, fontColor.g!, fontColor.b!);
|
|
|
+ }
|
|
|
+ final backgroundColor = inputText.background;
|
|
|
+ if (backgroundColor != null) {
|
|
|
+ _backgroundColor = Color.fromARGB(backgroundColor.a!, backgroundColor.r!,
|
|
|
+ backgroundColor.g!, backgroundColor.b!);
|
|
|
+ }
|
|
|
+
|
|
|
+ final fontName = inputText.fontName;
|
|
|
+
|
|
|
+ final fontStyles = inputText.fontStyles;
|
|
|
+ _lineLength = inputText.lineLength;
|
|
|
+ _lineWidth = inputText.lineWidth;
|
|
|
+ _textWrap = inputText.textWrap;
|
|
|
+ _fontSize = PtToPxConverter.ptToPx(inputText.fontSize);
|
|
|
+ _height = _fontSize! > 30 ? 36.5 : 22;
|
|
|
+
|
|
|
+ print(_lineLength);
|
|
|
+ super.initState();
|
|
|
+ }
|
|
|
+
|
|
|
+ @override
|
|
|
+ Widget build(BuildContext context) {
|
|
|
+ final _textStyle = TextStyle(
|
|
|
+ fontSize: PtToPxConverter.ptToPx(inputText.fontSize),
|
|
|
+ color: _fontColor,
|
|
|
+ );
|
|
|
+ return Container(
|
|
|
+ width: PtToPxConverter.ptToPx(_lineWidth!),
|
|
|
+ height: _textWrap! ? _height! * 4 : (_height! + 5),
|
|
|
+ padding: EdgeInsets.only(top: _textWrap! ? 10 : 5, right: 5, left: 5),
|
|
|
+ decoration: BoxDecoration(
|
|
|
+ border: Border.all(
|
|
|
+ width: 1,
|
|
|
+ color: Colors.grey,
|
|
|
+ ),
|
|
|
+ color: _backgroundColor,
|
|
|
+ ),
|
|
|
+ alignment: Alignment.center,
|
|
|
+ child: TextField(
|
|
|
+ focusNode: _focusNode,
|
|
|
+ readOnly: inputText.isReadOnly ?? false,
|
|
|
+ cursorHeight: _height!,
|
|
|
+ decoration: InputDecoration.collapsed(
|
|
|
+ hintText: '',
|
|
|
+ hintStyle: TextStyle(
|
|
|
+ fontSize: _fontSize,
|
|
|
+ color: Colors.black54,
|
|
|
+ ),
|
|
|
+ fillColor: _backgroundColor,
|
|
|
+ filled: true,
|
|
|
+ ),
|
|
|
+ textAlignVertical:
|
|
|
+ VerticalAlignmentToAlignVertical.VerticalAlignmentConvert(
|
|
|
+ inputText.verticalAlignment),
|
|
|
+ maxLines: _textWrap! ? 6 : 1,
|
|
|
+ minLines: _textWrap! ? 6 : 1,
|
|
|
+ controller: _controller,
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ static Size boundingTextSize(String text, TextStyle style,
|
|
|
+ {int maxLines = 2 ^ 31, double maxWidth = double.infinity}) {
|
|
|
+ if (text == null || text.isEmpty) {
|
|
|
+ return Size.zero;
|
|
|
+ }
|
|
|
+ final TextPainter textPainter = TextPainter(
|
|
|
+ textDirection: TextDirection.ltr,
|
|
|
+ text: TextSpan(text: text, style: style),
|
|
|
+ maxLines: maxLines)
|
|
|
+ ..layout(maxWidth: maxWidth);
|
|
|
+ return textPainter.size;
|
|
|
+ }
|
|
|
+}
|