comment_item_widget.dart 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_riverpod/flutter_riverpod.dart';
  3. import 'package:flutter_screenutil/flutter_screenutil.dart';
  4. import 'package:news_app/constant/color_res.dart';
  5. import 'package:news_app/extension/base.dart';
  6. import '../../model/new_comment_model.dart';
  7. import '../../widget/auth_gesture_detector.dart';
  8. /// @author: bo.zeng
  9. /// @email: cnhbwds@gmail.com
  10. /// @date: 2025 2025/4/17 12:22
  11. /// @description:
  12. class CommentItemWidget extends ConsumerStatefulWidget {
  13. //加一个回调函数
  14. final Function(int, String)? onTap;
  15. final Function(int)? onLongTap;
  16. final Comment comment;
  17. final int commentIndex;
  18. const CommentItemWidget(
  19. this.onTap,this.onLongTap,{
  20. super.key,
  21. required this.comment,
  22. required this.commentIndex,
  23. });
  24. @override
  25. ConsumerState<ConsumerStatefulWidget> createState() =>
  26. _CommentItemWidgetState();
  27. }
  28. class _CommentItemWidgetState extends ConsumerState<CommentItemWidget> {
  29. @override
  30. Widget build(BuildContext context) {
  31. return Column(
  32. crossAxisAlignment: CrossAxisAlignment.start,
  33. children: [
  34. Row(
  35. crossAxisAlignment: CrossAxisAlignment.start,
  36. children: [
  37. CircleAvatar(
  38. radius: 13.w,
  39. backgroundImage: NetworkImage(
  40. widget.comment.fromUser?.avatar ?? "",
  41. ),
  42. ),
  43. SizedBox(width: 5.w),
  44. Expanded(
  45. child: Column(
  46. crossAxisAlignment: CrossAxisAlignment.start,
  47. spacing: 4.h,
  48. children: [
  49. Text(
  50. widget.comment.fromUser?.nickname ?? "",
  51. style: TextStyle(
  52. fontWeight: FontWeight.bold,
  53. color: color333333,
  54. fontSize: 14.sp,
  55. ),
  56. ),
  57. Text(
  58. widget.comment.content ?? "",
  59. style: TextStyle(color: color333333, fontSize: 14.sp),
  60. ),
  61. Row(
  62. spacing: 10.w,
  63. children: [
  64. Text(
  65. widget.comment.createTime ?? "",
  66. style: TextStyle(color: color7788A0, fontSize: 12.sp),
  67. ),
  68. AuthGestureDetector(
  69. onTap: () {
  70. widget.onTap?.call(
  71. widget.commentIndex,
  72. widget.comment.fromUser?.nickname ?? "",
  73. );
  74. },
  75. child: Text(
  76. '回复',
  77. style: TextStyle(color: color333333, fontSize: 12.sp),
  78. ),
  79. ),
  80. SizedBox(width:5.w,),
  81. AuthGestureDetector(
  82. onTap: () {
  83. widget.onLongTap?.call(
  84. widget.commentIndex,
  85. );
  86. },
  87. child: Text(
  88. '举报',
  89. style: TextStyle(color: color333333, fontSize: 12.sp),
  90. ),
  91. ),
  92. ],
  93. ),
  94. ],
  95. ),
  96. ),
  97. ],
  98. ),
  99. if (widget.comment.subComment.isSafeData)
  100. Padding(
  101. padding: EdgeInsets.only(left: 30.w, top: 10.h),
  102. child: Column(
  103. crossAxisAlignment: CrossAxisAlignment.start,
  104. children:
  105. widget.comment.subComment!.map((sub) {
  106. return Padding(
  107. padding: EdgeInsets.only(bottom: 8.h),
  108. child: Row(
  109. crossAxisAlignment: CrossAxisAlignment.start,
  110. children: [
  111. CircleAvatar(
  112. radius: 13.w,
  113. backgroundImage: NetworkImage(
  114. widget.comment.fromUser?.avatar ?? "",
  115. ),
  116. ),
  117. SizedBox(width: 5.w),
  118. Expanded(
  119. child: Column(
  120. crossAxisAlignment: CrossAxisAlignment.start,
  121. spacing: 4.h,
  122. children: [
  123. Text(
  124. //'${reply.name} 回复 ${reply.replyTo}:',
  125. sub.fromUser?.nickname ?? "",
  126. style: TextStyle(
  127. fontWeight: FontWeight.bold,
  128. fontSize: 14.sp,
  129. ),
  130. ),
  131. Text(
  132. sub.content ?? "",
  133. style: TextStyle(fontSize: 14.sp),
  134. ),
  135. Row(
  136. spacing: 10.w,
  137. children: [
  138. Text(
  139. sub.createTime ?? "",
  140. style: TextStyle(
  141. color: color7788A0,
  142. fontSize: 12.sp,
  143. ),
  144. ),
  145. /* GestureDetector(
  146. onTap: () {
  147. widget.onTap?.call(
  148. widget.commentIndex,
  149. //reply.name,
  150. sub.fromUser?.nickname ?? "",
  151. );
  152. },
  153. child: Text(
  154. '回复',
  155. style: TextStyle(
  156. color: color333333,
  157. fontSize: 12.sp,
  158. ),
  159. ),
  160. ),*/
  161. ],
  162. ),
  163. ],
  164. ),
  165. ),
  166. ],
  167. ),
  168. );
  169. }).toList(),
  170. ),
  171. ),
  172. ],
  173. );
  174. }
  175. }