input_imageList.dart 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import 'package:fis_lib_report/converts/margin_convert.dart';
  2. import 'package:fis_lib_report/converts/pt_to_px_converter.dart';
  3. import 'package:fis_lib_report/pages/components/vid_image.dart';
  4. import 'package:fis_lib_report/pages/helpler.dart';
  5. import 'package:fis_lib_report/report/inputImageList.dart';
  6. import 'package:fis_lib_report/report_info/input_image_list_info.dart';
  7. import 'package:fis_lib_report/report_info/report_info.dart';
  8. import 'package:flutter/cupertino.dart';
  9. import 'package:flutter/material.dart';
  10. class RInputImageList extends StatefulWidget {
  11. final InputImageList inputImageList;
  12. RInputImageList(this.inputImageList);
  13. @override
  14. State<StatefulWidget> createState() {
  15. return _RInputImageListState();
  16. }
  17. }
  18. class _RInputImageListState extends State<RInputImageList> {
  19. InputImageList? inputImageList;
  20. InputImageListInfo? inputImageListInfo;
  21. Color _borderColor = Colors.grey;
  22. bool _isSelected = false;
  23. final List<String> _images = [];
  24. double _height = 0.0;
  25. Widget _child = const Text('请点击此处后选择图片');
  26. @override
  27. initState() {
  28. _initDatas();
  29. super.initState();
  30. }
  31. @override
  32. Widget build(BuildContext context) {
  33. if (inputImageListInfo != null) {
  34. final imageInfo = ReportInfo.instance
  35. .getBlockElement(widget.inputImageList) as InputImageListInfo;
  36. if (imageInfo != inputImageListInfo) {
  37. inputImageListInfo = imageInfo;
  38. setState(() {
  39. _images.clear();
  40. _isSelected = false;
  41. _child = _getChild();
  42. });
  43. inputImageListInfo!.onSelect!.addListener((sender, e) {
  44. setState(() {
  45. if (_images.contains(e)) {
  46. _images.remove(e);
  47. inputImageListInfo!.selectedImages.remove(e);
  48. } else {
  49. _images.add(e);
  50. inputImageListInfo!.selectedImages.add(e);
  51. }
  52. _child = _getChild();
  53. });
  54. });
  55. }
  56. }
  57. return SizedBox(
  58. width: PtToPxConverter.ptToPx(
  59. inputImageList!.imageWidth! * inputImageList!.column!),
  60. child: MouseRegion(
  61. cursor: SystemMouseCursors.click,
  62. child: GestureDetector(
  63. onTap: () {
  64. if (_isSelected) {
  65. setState(() {
  66. _borderColor = Colors.grey;
  67. _isSelected = false;
  68. inputImageListInfo!.isSelected = false;
  69. });
  70. } else {
  71. setState(() {
  72. _borderColor = const Color.fromARGB(255, 64, 159, 248);
  73. _isSelected = true;
  74. inputImageListInfo!.isSelected = true;
  75. });
  76. }
  77. },
  78. child: Container(
  79. padding: const EdgeInsets.symmetric(vertical: 3),
  80. height: _height,
  81. width: PtToPxConverter.ptToPx(
  82. inputImageList!.imageWidth! * inputImageList!.column!),
  83. alignment: Alignment.center,
  84. margin: MarginConvert.marginConvert(inputImageList!.margin),
  85. decoration: BoxDecoration(
  86. border: _isSelected
  87. ? Border.all(
  88. width: 0.5,
  89. color: _borderColor,
  90. )
  91. : null,
  92. color: Colors.transparent),
  93. child: _child,
  94. ),
  95. ),
  96. ),
  97. );
  98. }
  99. Widget _getChild() {
  100. if (_images.isNotEmpty) {
  101. final rowCount = (_images.length / inputImageList!.column!).ceil();
  102. _height = rowCount *
  103. (PtToPxConverter.ptToPx(inputImageList!.imageHeight!) + 3) +
  104. 6;
  105. return GridView.builder(
  106. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  107. crossAxisCount: inputImageList!.column!,
  108. crossAxisSpacing: 5,
  109. mainAxisSpacing: 5,
  110. childAspectRatio:
  111. inputImageList!.imageWidth! / inputImageList!.imageHeight!,
  112. ),
  113. itemCount: _images.length,
  114. itemBuilder: (BuildContext context, int index) {
  115. return VidImageView.network(
  116. _images[index],
  117. fit: BoxFit.fill,
  118. width: PtToPxConverter.ptToPx(inputImageList!.imageWidth!) - 20,
  119. );
  120. },
  121. );
  122. } else {
  123. _height = PtToPxConverter.ptToPx(inputImageList!.imageHeight!) + 9;
  124. }
  125. return const Text('请点击此处后选择图片');
  126. }
  127. @override
  128. void dispose() {
  129. inputImageListInfo!.onSelect!.dispose();
  130. super.dispose();
  131. }
  132. void _initDatas() {
  133. inputImageList = widget.inputImageList;
  134. _height = PtToPxConverter.ptToPx(inputImageList!.imageHeight) + 6;
  135. final element = ReportInfo.instance.getBlockElement(inputImageList!);
  136. if (element != null) {
  137. inputImageListInfo = element as InputImageListInfo;
  138. inputImageListInfo!.onSelect!.addListener((sender, e) {
  139. setState(() {
  140. if (_images.contains(e)) {
  141. _images.remove(e);
  142. inputImageListInfo!.selectedImages.remove(e);
  143. } else {
  144. _images.add(e);
  145. inputImageListInfo!.selectedImages.add(e);
  146. }
  147. _child = _getChild();
  148. });
  149. });
  150. }
  151. }
  152. }