input_imageList.dart 4.0 KB

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