user_evaluate_card_item.dart 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. import 'dart:math';
  2. import 'package:auto_route/src/route/page_route_info.dart';
  3. import 'package:cs_resources/theme/app_colors_theme.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:flutter/widgets.dart';
  6. import 'package:plugin_basic/modules/global_web_page.dart';
  7. import 'package:plugin_basic/modules/preview_photo_page.dart';
  8. import 'package:plugin_basic/router/basic_page_router.dart';
  9. import 'package:plugin_platform/engine/image/image_preview.dart';
  10. import 'package:router/componentRouter/component_service_manager.dart';
  11. import 'package:router/ext/auto_router_extensions.dart';
  12. import 'package:shared/utils/color_utils.dart';
  13. import 'package:shared/utils/goto_page.dart';
  14. import 'package:shared/utils/log_utils.dart';
  15. import 'package:widgets/ext/ex_widget.dart';
  16. import 'package:widgets/my_load_image.dart';
  17. import 'package:widgets/my_text_view.dart';
  18. import 'package:widgets/widget_export.dart';
  19. class UserEvaluateCardItem extends StatelessWidget {
  20. final String? useInSence; // 默认evaluateList 页面 可选值cleanDetailPage
  21. final String? id;
  22. final String name;
  23. final String avator;
  24. final String time;
  25. final double? score;
  26. final String content;
  27. final List<dynamic>? imageUrls;
  28. int? rowMaxImageNum;
  29. int? contentTextMaxLines;
  30. bool? isPreviewImage;
  31. UserEvaluateCardItem({
  32. Key? key,
  33. this.useInSence = 'evaluateList',
  34. this.id,
  35. required this.name,
  36. required this.avator,
  37. required this.time,
  38. this.score = 5.0,
  39. required this.content,
  40. this.imageUrls,
  41. this.rowMaxImageNum = 3,
  42. this.contentTextMaxLines = 3,
  43. this.isPreviewImage = true,
  44. }) : super(key: key);
  45. @override
  46. Widget build(BuildContext context) {
  47. List imageUrlsList = [];
  48. if(imageUrls != null && imageUrls!.isNotEmpty){
  49. // dart 取出 imageUrls 里面的前 rowMaxImageNum 张图片
  50. imageUrlsList = imageUrls!.take(rowMaxImageNum!).toList();
  51. }
  52. int totalImageCount = imageUrls!.length;
  53. int otherImageCount = imageUrls!.length - rowMaxImageNum!;
  54. int rowActualImageCount = imageUrls!.length > rowMaxImageNum! ? rowMaxImageNum! : imageUrls!.length;
  55. double avatorWidth = useInSence == 'evaluateList'? 45: 35;
  56. double avatorHeight = useInSence == 'evaluateList'? 45: 35;
  57. double nameFontSize = useInSence == 'evaluateList'? 18: 15;
  58. double starSize = useInSence == 'evaluateList'? 13.5: 12;
  59. double timeFontSize = useInSence == 'evaluateList'? 13: 10;
  60. double contentFontSize = useInSence == 'evaluateList'? 15: 11;
  61. double imageHeight = useInSence == 'evaluateList'? 87: 70;
  62. return Container(
  63. child: Column(
  64. children: [
  65. Container(
  66. width: double.infinity,
  67. // color: Colors.blue,
  68. child: Row(
  69. mainAxisAlignment: MainAxisAlignment.start,
  70. crossAxisAlignment: CrossAxisAlignment.start,
  71. mainAxisSize: MainAxisSize.max,
  72. children: [
  73. MyLoadImage(
  74. avator,
  75. width: avatorWidth,
  76. height: avatorHeight,
  77. isCircle: true,
  78. fit: BoxFit.cover,
  79. ).onTap(() {
  80. // 点击头像
  81. }),
  82. Expanded(
  83. child: Container(
  84. // color: Colors.yellow,
  85. margin: const EdgeInsets.only(left: 10),
  86. child: Column(
  87. mainAxisAlignment: MainAxisAlignment.start,
  88. crossAxisAlignment: CrossAxisAlignment.start,
  89. children: [
  90. MyTextView(
  91. name,
  92. isFontMedium: true,
  93. fontSize: nameFontSize,
  94. textColor: context.appColors.textBlack,
  95. maxLines: 1,
  96. isTextEllipsis: true,
  97. ),
  98. Row(
  99. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  100. crossAxisAlignment: CrossAxisAlignment.center,
  101. children: [
  102. // 评分显示
  103. Wrap(
  104. crossAxisAlignment: WrapCrossAlignment.center,
  105. spacing: 5,
  106. children: [
  107. AnimatedRatingStars(
  108. initialRating: score!,
  109. onChanged: (rating) {
  110. },
  111. readOnly: true,
  112. displayRatingValue: true, // Display the rating value
  113. interactiveTooltips: true, // Allow toggling half-star state
  114. customFilledIcon: Icons.star,
  115. customHalfFilledIcon: Icons.star_half,
  116. customEmptyIcon: Icons.star_border,
  117. filledColor: ColorUtils.string2Color("#FF0000"),
  118. starSize: starSize,
  119. animationDuration: const Duration(milliseconds: 0),
  120. animationCurve: Curves.easeInOut,
  121. ),
  122. MyTextView(
  123. '${score!}',
  124. isFontRegular: true,
  125. fontSize: 12,
  126. textColor: ColorUtils.string2Color('#767676'),
  127. maxLines: 1,
  128. isTextEllipsis: true,
  129. ),
  130. ],
  131. ),
  132. MyTextView(
  133. time,
  134. isFontRegular: true,
  135. fontSize: timeFontSize,
  136. textColor: ColorUtils.string2Color('#767676'),
  137. maxLines: 1,
  138. isTextEllipsis: true,
  139. ),
  140. ],
  141. ),
  142. ],
  143. ),
  144. ),
  145. ),
  146. ],
  147. ),
  148. ),
  149. const SizedBox(height: 12,),
  150. Container(
  151. width: double.infinity,
  152. // color: Colors.red,
  153. child: Column(
  154. crossAxisAlignment: CrossAxisAlignment.start,
  155. children: [
  156. MyTextView(
  157. content,
  158. textColor: context.appColors.textBlack,
  159. fontSize: contentFontSize,
  160. maxLines: contentTextMaxLines,
  161. textAlign: TextAlign.left,
  162. isTextEllipsis: true,
  163. ),
  164. const SizedBox(height: 12),
  165. // 图片
  166. LayoutBuilder(
  167. builder: (BuildContext context, BoxConstraints constraints) {
  168. final maxHeight = constraints.maxHeight;
  169. final minHeight = constraints.minHeight;
  170. final maxWidth = constraints.maxWidth;
  171. // Log.d("---maxHeight-----$maxHeight-- $minHeight $maxWidth--");
  172. return _buildImageSection(
  173. context,
  174. isPreviewImage!,
  175. maxWidth,
  176. imageUrlsList,
  177. imageUrls,
  178. totalImageCount,
  179. otherImageCount,
  180. rowMaxImageNum!,
  181. imageHeight
  182. );
  183. }
  184. )
  185. ]
  186. )
  187. ),
  188. ],
  189. ),
  190. );
  191. }
  192. Widget _buildImageSection(BuildContext context,bool isPreviewImage, double maxWidth, List? imageUrls,List? totalImageUrls, int totalImageCount, int otherImageCount, int rowMaxImageNum, double imageHeight) {
  193. if (imageUrls != null && imageUrls!.isNotEmpty) {
  194. final imageCount = imageUrls.length;
  195. return SizedBox(
  196. width: maxWidth,
  197. height: imageHeight,
  198. child: Row(
  199. mainAxisAlignment: MainAxisAlignment.start,
  200. children: List.generate(
  201. imageUrls.length,
  202. (index) => Container(
  203. height: imageHeight,
  204. width: (totalImageCount < rowMaxImageNum)? maxWidth/rowMaxImageNum - 16 : maxWidth/imageCount - 16,
  205. margin: EdgeInsets.only(right: (index!=imageCount-1) ? 16 : 0 ),
  206. color: ColorUtils.string2Color("#F2F3F6"),
  207. child:Stack(
  208. children: [
  209. Hero(
  210. tag: imageUrls[index],
  211. child: MyLoadImage(
  212. imageUrls[index],
  213. height: 87,
  214. // width: maxWidth/imageCount - 16,
  215. width: (totalImageCount < rowMaxImageNum)? maxWidth/rowMaxImageNum - 16 : maxWidth/imageCount - 16,
  216. fit: BoxFit.cover,
  217. // fit:BoxFit.fitWidth,
  218. cornerRadius: 5,
  219. onClick: (){
  220. if(isPreviewImage){
  221. // 点击图片预览
  222. // 过滤掉非字符串类型的元素
  223. List<String> filteredImages = totalImageUrls?.whereType<String>().toList() ?? [];
  224. // PreviewPhotoPage.startInstance(context: context, images: filteredImages, position: index);
  225. // context.appRouter.push(PreviewPhotoPageRoute(images: filteredImages, position: index));
  226. // ImagePreviewEngine.multipleImagePreview(
  227. // context,
  228. // filteredImages,
  229. // heroes: List.generate(filteredImages.length, (index) => filteredImages[index]),
  230. // onLongPressAction: (url) {}
  231. // );
  232. GotoPage.pushPageByFade(
  233. context: context,
  234. targetPage:
  235. PreviewPhotoPage(images: filteredImages, position: index),
  236. );
  237. }
  238. },
  239. ),
  240. ),
  241. otherImageCount > 0 && index == imageCount-1 ?
  242. Positioned(
  243. bottom: 0,
  244. right: 0,
  245. child: Container(
  246. padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 2),
  247. color: context.appColors.textBlack.withOpacity(0.5),
  248. child: MyTextView(
  249. "+$otherImageCount",
  250. textColor: Colors.white,
  251. fontSize: 12,
  252. ),
  253. ),
  254. ): const SizedBox.shrink(),
  255. ]
  256. )
  257. ),
  258. )
  259. )
  260. );
  261. } else {
  262. return const SizedBox.shrink();
  263. }
  264. }
  265. }