1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- 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/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:flutter/material.dart';
- class RStaticText extends StatefulWidget {
- RStaticText(this.staticText);
- final StaticText staticText;
- @override
- State<StatefulWidget> createState() {
- return _RStaticTextState();
- }
- }
- class _RStaticTextState extends State<RStaticText> {
- _RStaticTextState();
- 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
- Widget build(BuildContext context) {
- initDatas();
- final text = _staticTextInfo!.text!;
- return Container(
- margin: _margin,
- width: widget.staticText.lineWidth! > 0
- ? PtToPxConverter.ptToPx(widget.staticText.lineWidth!) - 2
- : null,
- child: Text(
- (text),
- style: _style,
- ),
- );
- }
- void initDatas() {
- final staticTextInfo =
- ReportInfo.instance.getElementInfo(widget.staticText);
- if (staticTextInfo != null) {
- _staticTextInfo = staticTextInfo as StaticTextInfo;
- }
- _fontSize = widget.staticText.fontSize ?? 15.0;
- //TODO(Loki):常规模板暂未设置fontStyles,后续再支持
- //final fontStyles = staticText.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!);
- }
- 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),
- color: _fontColor,
- backgroundColor: _backgroundColor,
- );
- }
- }
|