input_imageList.dart 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. late final InputImageList inputImageList;
  20. InputImageListInfo? inputImageListInfo;
  21. Color _borderColor = Colors.grey;
  22. bool _isSelected = false;
  23. bool _hasImageBorder = false;
  24. final List<String> _images = [];
  25. double _height = 0.0;
  26. Widget _child = const Text('请点击此处后选择右侧图片');
  27. @override
  28. initState() {
  29. inputImageList = widget.inputImageList;
  30. _hasImageBorder = inputImageList.hasImageBorder!;
  31. _height = PtToPxConverter.ptToPx(inputImageList.imageHeight) + 6;
  32. final element = ReportInfo.instance.getBlockElement(inputImageList);
  33. if (element != null) {
  34. inputImageListInfo = element as InputImageListInfo;
  35. inputImageListInfo!.onSelect!.addListener((sender, e) {
  36. setState(() {
  37. if (_images.contains(e)) {
  38. _images.remove(e);
  39. } else {
  40. _images.add(e);
  41. }
  42. _child = _getChild();
  43. });
  44. });
  45. }
  46. super.initState();
  47. }
  48. @override
  49. Widget build(BuildContext context) {
  50. return MouseRegion(
  51. cursor: SystemMouseCursors.click,
  52. child: GestureDetector(
  53. onTap: () {
  54. if (_isSelected) {
  55. setState(() {
  56. _borderColor = Colors.grey;
  57. _isSelected = false;
  58. _hasImageBorder = false;
  59. inputImageListInfo!.isSelected = false;
  60. });
  61. } else {
  62. setState(() {
  63. _borderColor = const Color.fromARGB(255, 64, 159, 248);
  64. _isSelected = true;
  65. _hasImageBorder = true;
  66. inputImageListInfo!.isSelected = true;
  67. });
  68. }
  69. },
  70. child: Container(
  71. padding: const EdgeInsets.all(3),
  72. height: _height,
  73. width: PtToPxConverter.ptToPx(
  74. inputImageList.imageWidth! * inputImageList.column!),
  75. alignment: Alignment.center,
  76. margin: MarginConvert.marginConvert(inputImageList.margin),
  77. decoration: BoxDecoration(
  78. border: _hasImageBorder
  79. ? Border.all(
  80. width: 0.5,
  81. color: _borderColor,
  82. )
  83. : null,
  84. color: Colors.transparent),
  85. child: _child,
  86. ),
  87. ),
  88. );
  89. }
  90. Widget _getChild() {
  91. if (_images.isNotEmpty) {
  92. final rowCount = (_images.length / 2).ceil();
  93. _height =
  94. rowCount * (PtToPxConverter.ptToPx(inputImageList.imageHeight!) + 3) +
  95. 6;
  96. return GridView.builder(
  97. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  98. crossAxisCount: inputImageList.column!,
  99. crossAxisSpacing: 5,
  100. mainAxisSpacing: 5,
  101. childAspectRatio:
  102. inputImageList.imageWidth! / inputImageList.imageHeight!,
  103. ),
  104. itemCount: _images.length,
  105. itemBuilder: (BuildContext context, int index) {
  106. return VidImageView.network(
  107. _images[index],
  108. fit: BoxFit.fill,
  109. width: PtToPxConverter.ptToPx(inputImageList.imageWidth!) - 20,
  110. );
  111. },
  112. );
  113. }
  114. return const Text('请点击此处后选择右侧图片');
  115. }
  116. @override
  117. void dispose() {
  118. inputImageListInfo!.onSelect!.dispose();
  119. super.dispose();
  120. }
  121. }