12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- import 'dart:convert';
- import 'dart:typed_data';
- import 'package:fis_lib_report/converts/alignment_convert.dart';
- 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/report/staticText.dart';
- import 'package:flutter/material.dart';
- class RStaticText extends StatefulWidget {
- RStaticText(this.staticText);
- final StaticText? staticText;
- @override
- State<StatefulWidget> createState() {
- return _RStaticTextState(staticText!);
- }
- }
- class _RStaticTextState extends State<RStaticText> {
- final StaticText staticText;
- _RStaticTextState(this.staticText);
- 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);
- @override
- initState() {
- _fontSize = staticText.fontSize ?? 15.0;
- //TODO(Loki):常规模板暂未设置fontStyles,后续再支持
- //final fontStyles = staticText.fontStyles;
- final fontColor = staticText.fontColor;
- if (fontColor != null) {
- _fontColor = Color.fromARGB(
- fontColor.a!, fontColor.r!, fontColor.g!, fontColor.b!);
- }
- final backgroundColor = staticText.background;
- if (backgroundColor != null) {
- _backgroundColor = Color.fromARGB(backgroundColor.a!, backgroundColor.r!,
- backgroundColor.g!, backgroundColor.b!);
- }
- final margin = 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),
- color: _fontColor,
- backgroundColor: _backgroundColor,
- );
- super.initState();
- }
- @override
- Widget build(BuildContext context) {
- final text = staticText.text!;
- return Container(
- margin: _margin,
- child: Text(
- _syncText(text),
- style: _style,
- ),
- );
- }
- String _syncText(String value) {
- try {
- if (value.contains(' ')) {
- String result = '';
- for (var i = 0; i < value.length; i++) {
- if (value[i] == ' ') {
- result += value[i] + ' ';
- } else {
- result += value[i];
- }
- }
- return result;
- } else {
- return value;
- }
- } catch (e) {
- print(e);
- return value;
- }
- }
- }
|