newsfeed_card_content.dart 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import 'package:cpt_community/components/comments_dialog.dart';
  2. import 'package:cs_resources/theme/app_colors_theme.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter/widgets.dart';
  5. import 'package:shared/utils/color_utils.dart';
  6. import 'package:shared/utils/log_utils.dart';
  7. import 'package:widgets/ext/ex_widget.dart';
  8. import 'package:widgets/my_load_image.dart';
  9. import 'package:widgets/my_text_view.dart';
  10. // 'id':1,
  11. // 'avator': Assets.communityCamera,
  12. // 'title': 'William Jefferson',
  13. // 'isFollow': false,
  14. // 'content': 'She said YES and our lives changed.Thank you all for coming to my propose today.We hope everyone can ……[More]',
  15. // 'imageUrls': ['https://img2.baidu.com/it/u=3489233687,2364672159&fm=253&fmt=auto&app=120&f=JPEG?w=507&h=500','https://img2.baidu.com/it/u=3489233687,2364672159&fm=253&fmt=auto&app=120&f=JPEG?w=507&h=500','https://img2.baidu.com/it/u=3489233687,2364672159&fm=253&fmt=auto&app=120&f=JPEG?w=507&h=500'],
  16. // 'time': 'June 17,2016 at 7:23 p.m.',
  17. // 'likeno': 12
  18. class NewsFeedCardContent extends StatelessWidget {
  19. final String content;
  20. final List? imageUrls;
  21. int? rowMaxImageNum=3;
  22. int? textMaxLines = 3;
  23. NewsFeedCardContent({
  24. Key? key,
  25. required this.content,
  26. this.imageUrls,
  27. this.rowMaxImageNum = 3,
  28. this.textMaxLines = 3
  29. }) : super(key: key);
  30. @override
  31. Widget build(BuildContext context) {
  32. List imageUrlsList = [];
  33. if(imageUrls != null && imageUrls!.isNotEmpty){
  34. // dart 取出 imageUrls 里面的前三张图片
  35. imageUrlsList = imageUrls!.take(rowMaxImageNum!).toList();
  36. }
  37. int totalImageCount = imageUrls!.length;
  38. int otherImageCount = imageUrls!.length - rowMaxImageNum!;
  39. int rowActualImageCount = imageUrls!.length > rowMaxImageNum! ? rowMaxImageNum! : imageUrls!.length;
  40. return LayoutBuilder(
  41. builder: (BuildContext context, BoxConstraints constraints) {
  42. final maxHeight = constraints.maxHeight;
  43. final minHeight = constraints.minHeight;
  44. final maxWidth = constraints.maxWidth;
  45. Log.d("---maxHeight-----$maxHeight-- $minHeight $maxWidth--");
  46. return Container(
  47. width: double.infinity,
  48. padding: const EdgeInsets.symmetric(horizontal: 15),
  49. child: Column(
  50. children: [
  51. MyTextView(
  52. content,
  53. textColor: context.appColors.textBlack,
  54. fontSize: 15,
  55. maxLines: textMaxLines,
  56. isTextEllipsis: true,
  57. ),
  58. const SizedBox(height: 12),
  59. // 图片
  60. _buildImageSection(context,maxWidth - 15, imageUrlsList, totalImageCount,otherImageCount),
  61. ]
  62. )
  63. );
  64. }
  65. );
  66. }
  67. Widget _buildImageSection(BuildContext context,double maxWidth, List? imageUrls, int totalImageCount, int otherImageCount) {
  68. if (imageUrls != null && imageUrls!.isNotEmpty) {
  69. final imageCount = imageUrls.length;
  70. return SizedBox(
  71. width: maxWidth,
  72. height: 87,
  73. child: Row(
  74. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  75. children: List.generate(
  76. imageUrls.length,
  77. (index) => Container(
  78. height: 87,
  79. width: maxWidth/imageCount - 16 * (imageCount-1),
  80. margin: EdgeInsets.only(right: (index!=imageCount-1) ? 16 : 0 ),
  81. color: ColorUtils.string2Color("#F2F3F6"),
  82. // color: Colors.red,
  83. child:Stack(
  84. children: [
  85. MyLoadImage(
  86. imageUrls[index],
  87. width: maxWidth/imageCount - (16 * imageCount-1),
  88. height: 87,
  89. fit: BoxFit.cover,
  90. cornerRadius: 5,
  91. ),
  92. otherImageCount > 0 && index == imageCount-1 ?
  93. Positioned(
  94. bottom: 0,
  95. right: 0,
  96. child: Container(
  97. padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 2),
  98. color: context.appColors.textBlack.withOpacity(0.5),
  99. child: MyTextView(
  100. "+$otherImageCount",
  101. textColor: Colors.white,
  102. fontSize: 12,
  103. ),
  104. ),
  105. ): const SizedBox.shrink(),
  106. ]
  107. )
  108. ),
  109. )
  110. )
  111. );
  112. } else {
  113. return const SizedBox.shrink();
  114. }
  115. }
  116. }