123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- import 'package:fis_lib_report/converts/pt_to_px_converter.dart';
- import 'package:fis_lib_report/converts/text_size_converter.dart';
- import 'package:fis_lib_report/converts/alignment_convert.dart';
- import 'package:fis_lib_report/report/inputText.dart';
- import 'package:fis_lib_report/report_info/element_info.dart';
- import 'package:fis_lib_report/report_info/input_text_info.dart';
- import 'package:fis_lib_report/report_info/report_info.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();
- }
- }
- class _RInputTextState extends State<RInputText> {
- _RInputTextState();
- late final InputText inputText;
- final _controller = TextEditingController();
- 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;
- TextStyle? _textStyle;
- InputTextInfo? _inputTextInfo;
- @override
- initState() {
- inputText = widget.inputText;
- final inputTextInfo = ReportInfo.instance.getElementInfo(inputText);
- _inputTextInfo = inputTextInfo as InputTextInfo;
- if (inputText.isReadOnly!) {
- _controller.text = 'test';
- }
- 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!);
- }
- _textStyle = TextStyle(
- fontSize: PtToPxConverter.ptToPx(inputText.fontSize),
- color: _fontColor,
- );
- //TODO(Loki):set FontName in TextField
- final fontName = inputText.fontName;
- //TODO(Loki):常规模板暂未设置fontStyles,后续再支持
- final fontStyles = inputText.fontStyles;
- _lineLength = inputText.lineLength;
- _lineWidth = inputText.lineWidth;
- _textWrap = inputText.textWrap;
- _fontSize = PtToPxConverter.ptToPx(inputText.fontSize);
- _height = _fontSize! > 30 ? 36.5 : 22;
- 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!),
- padding: EdgeInsets.only(top: _textWrap! ? 10 : 5, right: 5, left: 5),
- decoration: BoxDecoration(
- border: Border.all(
- width: 1,
- color: inputText.isReadOnly! ? Colors.transparent : Colors.grey,
- ),
- color: _backgroundColor,
- ),
- child: TextField(
- focusNode: _focusNode,
- readOnly: inputText.isReadOnly ?? false,
- // cursorHeight: _height!,
- decoration: InputDecoration.collapsed(
- hintText: '',
- hintStyle: TextStyle(
- fontSize: _fontSize,
- color: Colors.black54,
- ),
- fillColor: _backgroundColor,
- filled: false,
- ).copyWith(
- contentPadding: EdgeInsets.symmetric(vertical: _textWrap! ? 2.5 : 4),
- ),
- textAlignVertical: AlignmentConvert.verticalAlignmentConvert(
- inputText.verticalAlignment),
- minLines: 1,
- maxLines: _textWrap! ? 6 : 1,
- controller: _controller,
- textAlign: TextAlign.start,
- style: _textStyle,
- onChanged: (v) {
- _onInputChanged(_textStyle, v);
- },
- ),
- );
- }
- //onchange 事件
- void _onInputChanged(TextStyle _textStyle, String value) {
- if (_inputTextInfo != null) {
- _inputTextInfo!.text = value;
- }
- final width = TextSizeConvert.getTextSize(value, _textStyle).width;
- // ignore: todo
- //TODO(LOki):此处需要区分不同的输入框
- if (inputText.tag!.name == 'HospitalName') {
- if (_lineWidth! < width) {
- setState(() {
- if (width < 480) {
- _lineWidth = width;
- }
- });
- } else if (_controller.text.isEmpty) {
- setState(() {
- //重置长度
- _lineWidth = inputText.lineWidth;
- });
- } else if (TextSizeConvert.getTextSize(_controller.text, _textStyle)
- .width >
- inputText.lineWidth!) {
- setState(() {
- if (width < 480) {
- _lineWidth = width;
- }
- });
- }
- }
- }
- }
|