static_text.dart 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import 'dart:convert';
  2. import 'dart:typed_data';
  3. import 'package:fis_lib_report/converts/alignment_convert.dart';
  4. import 'package:fis_lib_report/converts/pt_to_px_converter.dart';
  5. import 'package:fis_lib_report/converts/text_size_converter.dart';
  6. import 'package:fis_lib_report/report/staticText.dart';
  7. import 'package:flutter/material.dart';
  8. class RStaticText extends StatefulWidget {
  9. RStaticText(this.staticText);
  10. final StaticText staticText;
  11. @override
  12. State<StatefulWidget> createState() {
  13. return _RStaticTextState();
  14. }
  15. }
  16. class _RStaticTextState extends State<RStaticText> {
  17. late final StaticText staticText;
  18. _RStaticTextState();
  19. double _fontSize = 15.0;
  20. TextStyle _style = const TextStyle();
  21. Color _fontColor = Colors.black;
  22. Color _backgroundColor = const Color.fromARGB(255, 255, 255, 255);
  23. EdgeInsets _margin = const EdgeInsets.all(0);
  24. @override
  25. initState() {
  26. staticText = widget.staticText;
  27. _fontSize = staticText.fontSize ?? 15.0;
  28. //TODO(Loki):常规模板暂未设置fontStyles,后续再支持
  29. //final fontStyles = staticText.fontStyles;
  30. final fontColor = staticText.fontColor;
  31. if (fontColor != null) {
  32. _fontColor = Color.fromARGB(
  33. fontColor.a!, fontColor.r!, fontColor.g!, fontColor.b!);
  34. }
  35. final backgroundColor = staticText.background;
  36. if (backgroundColor != null) {
  37. _backgroundColor = Color.fromARGB(backgroundColor.a!, backgroundColor.r!,
  38. backgroundColor.g!, backgroundColor.b!);
  39. }
  40. final margin = staticText.margin;
  41. if (margin != null) {
  42. _margin = EdgeInsets.only(
  43. top: margin.top ?? 0,
  44. bottom: margin.bottom ?? 0,
  45. left: margin.left ?? 0,
  46. right: margin.right ?? 0);
  47. }
  48. _style = TextStyle(
  49. fontSize: PtToPxConverter.ptToPx(_fontSize),
  50. color: _fontColor,
  51. backgroundColor: _backgroundColor,
  52. );
  53. super.initState();
  54. }
  55. @override
  56. Widget build(BuildContext context) {
  57. final text = staticText.text!;
  58. return Container(
  59. margin: _margin,
  60. child: Text(
  61. (text),
  62. style: _style,
  63. ),
  64. );
  65. }
  66. String _syncText(String value) {
  67. try {
  68. if (value.contains(' ')) {
  69. String result = '';
  70. for (var i = 0; i < value.length; i++) {
  71. if (value[i] == ' ') {
  72. result += value[i] + ' ';
  73. } else {
  74. result += value[i];
  75. }
  76. }
  77. return result;
  78. } else {
  79. return value;
  80. }
  81. } catch (e) {
  82. print(e);
  83. return value;
  84. }
  85. }
  86. }