topic_item_widget.dart 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import 'package:cached_network_image/cached_network_image.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_screenutil/flutter_screenutil.dart';
  4. import 'package:news_app/ui/topic/user_head_widget.dart';
  5. import '../../constant/color_res.dart';
  6. import '../../model/topic_item_model.dart';
  7. import '../../widget/auth_gesture_detector.dart';
  8. import '../../widget/my_txt.dart';
  9. /// @author: bo.zeng
  10. /// @email: cnhbwds@gmail.com
  11. /// @date: 2025 2025/4/9 16:00
  12. /// @description:
  13. class TopicItemWidget extends StatelessWidget {
  14. final TopicRecordModel? item;
  15. final bool isShow;
  16. final Function(String)? onLongTap;
  17. const TopicItemWidget(this.onLongTap,{super.key, required this.item, this.isShow = false});
  18. @override
  19. Widget build(BuildContext context) {
  20. return Container(
  21. padding: EdgeInsets.all(10.w),
  22. decoration: BoxDecoration(
  23. borderRadius: BorderRadius.circular(8.r),
  24. color: Colors.white,
  25. ),
  26. child: Column(
  27. crossAxisAlignment: CrossAxisAlignment.start,
  28. children: [
  29. UserHeadWidget(
  30. nickname: item?.member?.nickname ?? "",
  31. avatar: item?.member?.avatar ?? "",
  32. time: "2025/1/1",
  33. ),
  34. SizedBox(height: 10.h),
  35. Text.rich(
  36. TextSpan(
  37. text: item?.topic?.content ?? "",
  38. style: TextStyle(color: Colors.blue, fontSize: 15.sp),
  39. children: [
  40. WidgetSpan(child: SizedBox(width: 5.w)),
  41. TextSpan(
  42. text: item?.content ?? "",
  43. style: TextStyle(fontSize: 15.sp, color: Colors.black),
  44. ),
  45. ],
  46. ),
  47. ),
  48. SizedBox(height: 10.h),
  49. if (item?.resourceList?.isNotEmpty == true)
  50. buildImageByResource(item?.resourceList),
  51. if (item?.resourceList?.isNotEmpty == true) SizedBox(height: 10.h),
  52. Row(
  53. mainAxisAlignment: MainAxisAlignment.end,
  54. children: [
  55. if (isShow == true) AuthGestureDetector(
  56. onTap: () {
  57. onLongTap?.call(
  58. item?.contentId ?? '',
  59. );
  60. },
  61. child: Text(
  62. '举报',
  63. style: TextStyle(color: color333333, fontSize: 12.sp),
  64. ),
  65. ),
  66. if (isShow == true) SizedBox(width:15.w,),
  67. Icon(
  68. item?.isLiked == true ? Icons.favorite : Icons.favorite_border,
  69. color: item?.isLiked == true ? Colors.red : color666666,
  70. size: 14.w,
  71. ),
  72. myTxt(
  73. text: "${item?.likeNum ?? 0}",
  74. color: color666666,
  75. fontSize: 12.sp,
  76. ),
  77. SizedBox(width: 15.w),
  78. Icon(Icons.messenger_outline, color: color666666, size: 14.w),
  79. myTxt(
  80. text: "${item?.commentNum ?? 0}",
  81. color: color666666,
  82. fontSize: 12.sp,
  83. ),
  84. ],
  85. ),
  86. ],
  87. ),
  88. );
  89. }
  90. }
  91. Widget buildImageByResource(List<Resource>? resourceList) {
  92. if (resourceList == null || resourceList.isEmpty) {
  93. return const SizedBox.shrink();
  94. }
  95. Resource? imageResource = resourceList.firstWhere(
  96. (item) => item.type == "image",
  97. orElse: () => Resource(type: "", url: ""),
  98. );
  99. if (imageResource.url.isNotEmpty) {
  100. return CachedNetworkImage(
  101. imageUrl: imageResource.url,
  102. width: 211.h,
  103. height: 119.h,
  104. fit: BoxFit.cover,
  105. );
  106. } else {
  107. return const SizedBox.shrink();
  108. }
  109. }