paragraph_page.dart 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. import 'package:fis_lib_report/pages/components/multi_select.dart';
  2. import 'package:fis_lib_report/pages/helpler.dart';
  3. import 'package:fis_lib_report/report/dateTimeElement.dart';
  4. import 'package:fis_lib_report/report/element_type.dart';
  5. import 'package:fis_lib_report/report/inputText.dart';
  6. import 'package:fis_lib_report/report/interfaces/element.dart';
  7. import 'package:fis_lib_report/report/interfaces/position_layout.dart';
  8. import 'package:fis_lib_report/report/multiSelected.dart';
  9. import 'package:fis_lib_report/report/paragraph.dart';
  10. import 'package:fis_lib_report/report/singleSelected.dart';
  11. import 'package:fis_lib_report/report/staticText.dart';
  12. import 'package:flutter/cupertino.dart';
  13. import 'package:flutter/material.dart';
  14. class ParagraphPage extends StatefulWidget {
  15. final Paragraph paragraph;
  16. ParagraphPage({Key? key, required this.paragraph}) : super(key: key);
  17. @override
  18. State<StatefulWidget> createState() {
  19. return _ParagraphState();
  20. }
  21. }
  22. class _ParagraphState extends State<ParagraphPage> {
  23. final _controller = TextEditingController();
  24. List<IElement>? _elements = [];
  25. int _itemCount = 0;
  26. @override
  27. initState() {
  28. _elements = widget.paragraph.elements;
  29. _itemCount = _elements!.length;
  30. super.initState();
  31. }
  32. @override
  33. Widget build(BuildContext context) {
  34. if (_itemCount == 0) {
  35. return const SizedBox();
  36. }
  37. return Row(
  38. mainAxisAlignment:
  39. widget.paragraph.horizontalAlignment == HorizontalLayout.Center
  40. ? MainAxisAlignment.center
  41. : MainAxisAlignment.start,
  42. crossAxisAlignment: CrossAxisAlignment.start,
  43. children: [
  44. ..._elements!.map((element) {
  45. if (element.elementType!.name == ElementType.inputText!.name) {
  46. InputText inputText = element as InputText;
  47. return Container(
  48. color: Colors.white,
  49. width: inputText.lineWidth! * 1.5,
  50. height: inputText.lineWidth! / 3.5,
  51. child: TextField(
  52. decoration: const InputDecoration(
  53. isCollapsed: true,
  54. contentPadding:
  55. EdgeInsets.symmetric(vertical: 5, horizontal: 5),
  56. hintText: '',
  57. border: OutlineInputBorder(
  58. borderRadius: BorderRadius.all(Radius.circular(4.0)),
  59. ),
  60. ),
  61. maxLines: 6,
  62. controller: _controller,
  63. textAlign: TextAlign.start,
  64. style: const TextStyle(
  65. fontSize: 18,
  66. ),
  67. ),
  68. );
  69. } else if (element.elementType!.name ==
  70. ElementType.staticText!.name) {
  71. StaticText staticText = element as StaticText;
  72. return SizedBox(
  73. width: staticText.text!.length > 10 ? 300 : 110,
  74. child: Text(staticText.text!),
  75. );
  76. } else if (element.elementType!.name ==
  77. ElementType.singleSelected!.name) {
  78. SingleSelected singleSelected = element as SingleSelected;
  79. List<String>? values = singleSelected.items;
  80. if (values != null && values.isNotEmpty) {
  81. return SizedBox(
  82. width: 104,
  83. height: 30,
  84. child: DropdownButton(
  85. onChanged: (Object? value) {},
  86. items: values.map<DropdownMenuItem<String>>((String value) {
  87. return DropdownMenuItem<String>(
  88. value: value,
  89. child: Text(value),
  90. );
  91. }).toList(),
  92. ),
  93. );
  94. }
  95. } else if (element.elementType!.name == ElementType.line!.name) {
  96. return Container(
  97. margin: const EdgeInsets.symmetric(vertical: 10),
  98. padding: const EdgeInsets.symmetric(horizontal: 0),
  99. width: 760,
  100. child: const Divider(
  101. height: 1,
  102. thickness: 1,
  103. color: Colors.black,
  104. ),
  105. );
  106. } else if (element.elementType!.name == ElementType.dateTime!.name) {
  107. final dateTime = element as DateTimeElement;
  108. final currentDateTime = DateTime.now();
  109. final text = currentDateTime.toString().substring(0, 10);
  110. return Container(
  111. width: 110,
  112. child: Text(text),
  113. );
  114. } else if (element.elementType!.name ==
  115. ElementType.multiSelected!.name) {
  116. final multiSelected = element as MultiSelected;
  117. List<String>? values = multiSelected.items;
  118. return SizedBox(
  119. width: 120,
  120. height: 30,
  121. child: TextField(
  122. cursorWidth: 0,
  123. mouseCursor: SystemMouseCursors.click,
  124. decoration: const InputDecoration(
  125. suffixIcon: Icon(Icons.arrow_drop_down),
  126. ),
  127. onTap: () {
  128. _showMultiSelect(values);
  129. },
  130. ),
  131. );
  132. }
  133. return Container(
  134. height: 30,
  135. width: 80,
  136. decoration: BoxDecoration(
  137. border: Border.all(
  138. width: 0.5,
  139. color: const Color.fromARGB(255, 83, 83, 83),
  140. ),
  141. color: Colors.grey[200]),
  142. child: const Text('组件占位'),
  143. );
  144. }),
  145. ],
  146. );
  147. }
  148. void _showMultiSelect(List<String>? items) async {
  149. // a list of selectable items
  150. // these items can be hard-coded or dynamically fetched from a database/API
  151. if (items!.isEmpty) {
  152. return;
  153. }
  154. final List<String>? results = await showDialog(
  155. context: context,
  156. builder: (BuildContext context) {
  157. return MultiSelect(items: items);
  158. },
  159. );
  160. }
  161. }