123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- import 'package:fis_lib_report/converts/pt_to_px_converter.dart';
- import 'package:fis_lib_report/report/static_text.dart';
- import 'package:fis_lib_report/report_info/report_info.dart';
- import 'package:fis_lib_report/report_info/static_text_info.dart';
- import 'package:fis_ui/index.dart';
- import 'package:flutter/material.dart';
- class FStaticText extends StatefulWidget implements FWidget {
- const FStaticText(this.staticText, {Key? key}) : super(key: key);
- final StaticText staticText;
- @override
- State<StatefulWidget> createState() {
- return _FStaticTextState();
- }
- }
- class _FStaticTextState extends State<FStaticText> {
- _FStaticTextState();
- double _fontSize = 15.0;
- TextStyle _style = const TextStyle();
- Color _fontColor = Colors.black;
- Color _backgroundColor = const Color.fromARGB(255, 255, 255, 255);
- EdgeInsets _margin = const EdgeInsets.all(0);
- StaticTextInfo? _staticTextInfo;
- @override
- initState() {
- super.initState();
- }
- @override
- FWidget build(BuildContext context) {
- initDatas();
- String text =
- _staticTextInfo?.text.replaceAll(RegExp(r'[\r\n]+'), '') ?? '';
- List<FWidget> emptySpaces = [];
- final containsSpace = text.contains(' ');
- RegExp regex = RegExp(r"^\s+");
- var match = regex.firstMatch(text);
- int preTextSpacesConut = 0;
- if (match != null) {
- String spaces = match.group(0) ?? '';
- preTextSpacesConut = spaces.length;
- }
- if (containsSpace) {
- int trailingSpaces = text.length - text.trimRight().length;
- if (trailingSpaces >= 30) {
- text = text.trim();
- emptySpaces.add(FText(text));
- emptySpaces.add(const FExpanded(child: FSizedBox()));
- } else if (preTextSpacesConut >= 5 && !text.contains('检查医师')) {
- ///这个检查医师是为了兼容“苏州阳光护理院”这个模板中的空格
- emptySpaces.add(const FExpanded(child: FSizedBox()));
- text = text.trim();
- emptySpaces.add(FText(text));
- } else {
- for (var i = 0; i < text.length; i++) {
- if (text[i] != ' ') {
- emptySpaces.add(
- FText(
- text[i],
- style: _style,
- ),
- );
- } else {
- emptySpaces.add(FSizedBox(
- width: _fontSize > 20 ? 15 : 7.5,
- ));
- }
- }
- }
- }
- var aliment = CrossAxisAlignment.start;
- double? width = widget.staticText.lineWidth! > 0
- ? PtToPxConverter.ptToPx(widget.staticText.lineWidth!) - 3
- : null;
- if (widget.staticText.lineLength != null &&
- widget.staticText.lineLength! < 5 &&
- width != null) {
- if (widget.staticText.lineLength! <= 3 &&
- _fontSize <= 10.5 &&
- width > 90) {
- width = 60;
- } else {
- width = width - 2;
- }
- }
- return FColumn(
- mainAxisAlignment: MainAxisAlignment.center,
- crossAxisAlignment: aliment,
- children: [
- FContainer(
- margin: _margin,
- width: width,
- child: containsSpace
- ? FRow(mainAxisSize: MainAxisSize.min, children: emptySpaces)
- : FText(
- (text),
- style: _style,
- ),
- ),
- ],
- );
- }
- void initDatas() {
- final staticTextInfo =
- FReportInfo.instance.getElementInfo(widget.staticText);
- if (staticTextInfo != null) {
- _staticTextInfo = staticTextInfo as StaticTextInfo;
- }
- _fontSize = widget.staticText.fontSize ?? 15.0;
- //TODO(Loki):常规模板暂未设置fontStyles,后续再支持
- final fontColor = widget.staticText.fontColor;
- if (fontColor != null) {
- _fontColor = Color.fromARGB(
- fontColor.a!, fontColor.r!, fontColor.g!, fontColor.b!);
- }
- final backgroundColor = widget.staticText.background;
- if (backgroundColor != null) {
- _backgroundColor = Color.fromARGB(backgroundColor.a!, backgroundColor.r!,
- backgroundColor.g!, backgroundColor.b!);
- if (_backgroundColor == Colors.white) {
- _backgroundColor = Colors.transparent;
- }
- }
- final margin = widget.staticText.margin;
- if (margin != null) {
- _margin = EdgeInsets.only(
- top: margin.top ?? 0,
- bottom: margin.bottom ?? 0,
- left: margin.left ?? 0,
- right: margin.right ?? 0);
- }
- _style = TextStyle(
- fontSize: PtToPxConverter.ptToPx(_fontSize < 10 ? 8 : _fontSize),
- color: _fontColor,
- backgroundColor: _backgroundColor,
- );
- }
- }
|