paragraph_page.dart 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. import 'package:fis_lib_report/converts/alignment_convert.dart';
  2. import 'package:fis_lib_report/pages/components/datetime.dart';
  3. import 'package:fis_lib_report/pages/components/input_image.dart';
  4. import 'package:fis_lib_report/pages/components/input_text.dart';
  5. import 'package:fis_lib_report/pages/components/line.dart';
  6. import 'package:fis_lib_report/pages/components/multi_select.dart';
  7. import 'package:fis_lib_report/pages/components/multi_selected.dart';
  8. import 'package:fis_lib_report/pages/components/page_number.dart';
  9. import 'package:fis_lib_report/pages/components/single_select.dart';
  10. import 'package:fis_lib_report/pages/components/space.dart';
  11. import 'package:fis_lib_report/pages/components/static_Text.dart';
  12. import 'package:fis_lib_report/pages/components/static_image.dart';
  13. import 'package:fis_lib_report/pages/helpler.dart';
  14. import 'package:fis_lib_report/report/dateTimeElement.dart';
  15. import 'package:fis_lib_report/report/element_type.dart';
  16. import 'package:fis_lib_report/report/inputImage.dart';
  17. import 'package:fis_lib_report/report/inputText.dart';
  18. import 'package:fis_lib_report/report/interfaces/element.dart';
  19. import 'package:fis_lib_report/report/line.dart';
  20. import 'package:fis_lib_report/report/multiSelected.dart';
  21. import 'package:fis_lib_report/report/page_number.dart';
  22. import 'package:fis_lib_report/report/paragraph.dart';
  23. import 'package:fis_lib_report/report/rt_Cell.dart';
  24. import 'package:fis_lib_report/report/rt_table.dart';
  25. import 'package:fis_lib_report/report/singleSelected.dart';
  26. import 'package:fis_lib_report/report/space.dart';
  27. import 'package:fis_lib_report/report/static_text.dart';
  28. import 'package:fis_lib_report/report/static_image.dart';
  29. import 'package:flutter/material.dart';
  30. class ParagraphPage extends StatefulWidget {
  31. final Paragraph paragraph;
  32. ParagraphPage({Key? key, required this.paragraph}) : super(key: key);
  33. @override
  34. State<StatefulWidget> createState() {
  35. return _ParagraphState();
  36. }
  37. }
  38. class _ParagraphState extends State<ParagraphPage> {
  39. List<IElement>? _elements = [];
  40. int _itemCount = 0;
  41. @override
  42. initState() {
  43. super.initState();
  44. }
  45. @override
  46. Widget build(BuildContext context) {
  47. _elements = widget.paragraph.elements;
  48. _itemCount = _elements!.length;
  49. if (_itemCount == 0) {
  50. return const SizedBox();
  51. } else if (_itemCount == 2 &&
  52. _elements![0].elementType!.name == ElementType.staticText.name &&
  53. (_elements![1].elementType!.name == ElementType.singleSelected.name ||
  54. _elements![1].elementType!.name == ElementType.multiSelected.name ||
  55. _elements![1].elementType!.name == ElementType.inputText.name)) {
  56. try {
  57. final staticText = _elements![0];
  58. if (staticText.parent != null) {
  59. final paragraph = staticText.parent as Paragraph;
  60. if (paragraph.parent != null) {
  61. final cell = paragraph.parent as RTCell;
  62. if (cell.parent != null) {
  63. final table = cell.parent as RTTable;
  64. final values = table.cells!.values.toList();
  65. for (var i = 0; i < values.length; i++) {
  66. if (values[i] == cell) {
  67. final key = table.cells!.keys.toList()[i];
  68. final column = key.column;
  69. final width = table.columnDefinitions![column!].width;
  70. var valueWidth = 0.0;
  71. if (_elements![1].elementType!.name ==
  72. ElementType.inputText.name) {
  73. final input = _elements![1] as InputText;
  74. valueWidth = input.lineWidth!;
  75. }
  76. if (_elements![1].elementType!.name ==
  77. ElementType.singleSelected.name) {
  78. final input = _elements![1] as SingleSelected;
  79. valueWidth = input.lineWidth!;
  80. }
  81. if (_elements![1].elementType!.name ==
  82. ElementType.multiSelected.name) {
  83. final input = _elements![1] as MultiSelected;
  84. valueWidth = input.lineWidth!;
  85. }
  86. final textWidth = width! - valueWidth;
  87. final textElement = staticText as StaticText;
  88. textElement.lineWidth = textWidth;
  89. }
  90. }
  91. }
  92. }
  93. }
  94. } catch (e) {
  95. print(e);
  96. }
  97. }
  98. final margin = widget.paragraph.margin!;
  99. return Container(
  100. margin: EdgeInsets.only(
  101. top: margin.top!,
  102. bottom: margin.bottom!,
  103. left: margin.left!,
  104. right: margin.right!,
  105. ),
  106. alignment: AlignmentConvert.horizontalConvert(
  107. widget.paragraph.horizontalAlignment),
  108. child: Wrap(
  109. alignment: WrapAlignment.spaceEvenly,
  110. children: [
  111. ..._elements!.map((element) {
  112. if (element.elementType!.name == ElementType.inputText.name) {
  113. InputText inputText = element as InputText;
  114. return RInputText(inputText: inputText);
  115. } else if (element.elementType!.name ==
  116. ElementType.staticText.name) {
  117. StaticText staticText = element as StaticText;
  118. return RStaticText(staticText);
  119. } else if (element.elementType!.name ==
  120. ElementType.singleSelected.name) {
  121. SingleSelected singleSelected = element as SingleSelected;
  122. return RSingleSelected(singleSelected);
  123. } else if (element.elementType!.name == ElementType.line.name) {
  124. Line line = element as Line;
  125. return RLine(line);
  126. } else if (element.elementType!.name == ElementType.dateTime.name) {
  127. final dateTime = element as DateTimeElement;
  128. return RDateTime(dateTime);
  129. } else if (element.elementType!.name ==
  130. ElementType.multiSelected.name) {
  131. final multiSelected = element as MultiSelected;
  132. return RMultiSelected(multiSelected);
  133. } else if (element.elementType!.name ==
  134. ElementType.inputImage.name) {
  135. final inputImage = element as InputImage;
  136. return RInputImage(inputImage);
  137. } else if (element.elementType!.name ==
  138. ElementType.staticImage.name) {
  139. final staticImage = element as StaticImage;
  140. return RStaticImage(staticImage);
  141. } else if (element.elementType!.name == ElementType.space.name) {
  142. final space = element as Space;
  143. return RSpace(space);
  144. } else if (element.elementType!.name ==
  145. ElementType.pageNumber.name) {
  146. final pageNumber = element as PageNumber;
  147. return RPageNumber(pageNumber);
  148. }
  149. return Container(
  150. height: 30,
  151. width: 180,
  152. decoration: TestBoxDecoration.buildDecoration(),
  153. child: const Text('未知组件占位'),
  154. );
  155. }),
  156. ],
  157. ),
  158. );
  159. }
  160. void _showMultiSelect(List<String>? items) async {
  161. // a list of selectable items
  162. // these items can be hard-coded or dynamically fetched from a database/API
  163. if (items!.isEmpty) {
  164. return;
  165. }
  166. final List<String>? results = await showDialog(
  167. context: context,
  168. builder: (BuildContext context) {
  169. return MultiSelect(items: items);
  170. },
  171. );
  172. }
  173. }