news_list_item.dart 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_screenutil/flutter_screenutil.dart';
  4. import 'package:get/get.dart';
  5. import 'package:get/get_core/src/get_main.dart';
  6. import 'package:location/data/bean/message_info.dart';
  7. import 'package:location/utils/common_expand.dart';
  8. import '../../resource/assets.gen.dart';
  9. import '../../resource/colors.gen.dart';
  10. import '../../resource/string.gen.dart';
  11. import '../../utils/date_util.dart';
  12. typedef MessageFunCallback = void Function(MessageInfo info);
  13. Widget buildMessageInfoItem(MessageInfo item,MessageFunCallback callback,{VoidCallback? onReportEvent,bool? isShowReportButton}) {
  14. return buildMessageItem(Assets.images.iconDefaultFriendAvatar.provider(),
  15. title: item.senderPhone ?? '',
  16. content: getMessageContentTxt(item.type),
  17. contentTextStyle: getMessageContentTextStyle(item.type),
  18. createTime: item.createTime,
  19. bgGradient: getMessageBgGradient(item.type),
  20. onReportEvent: onReportEvent,
  21. isShowReportButton: isShowReportButton ?? false,
  22. statusWidget: getMessageStatusWidget(item.type, funClick: () {
  23. callback(item);
  24. }));
  25. }
  26. // 2:你的好友请求已经被接受
  27. // 3:你的好友请求已经被拒绝
  28. // 4:好友发来的求救
  29. // 5:你的好友删除了你
  30. Widget getMessageStatusWidget(int type, {VoidCallback? funClick}) {
  31. if (type == 2) {
  32. return Container(
  33. decoration: BoxDecoration(
  34. color: '#1F15CB4C'.color, borderRadius: BorderRadius.circular(4.w)),
  35. padding: EdgeInsets.symmetric(horizontal: 5.w, vertical: 3.w),
  36. child: Text(StringName.newsRequestAgree,
  37. style: TextStyle(fontSize: 12.sp, color: '#00BB70'.color, height: 1)),
  38. );
  39. } else if (type == 3) {
  40. return Container(
  41. decoration: BoxDecoration(
  42. color: '#1FCB1515'.color, borderRadius: BorderRadius.circular(4.w)),
  43. padding: EdgeInsets.symmetric(horizontal: 5.w, vertical: 3.w),
  44. child: Text(StringName.newsRequestDisagree,
  45. style: TextStyle(fontSize: 12.sp, color: '#FF2125'.color, height: 1)),
  46. );
  47. } else if (type == 4) {
  48. return GestureDetector(
  49. onTap: funClick,
  50. child: Container(
  51. width: 79.w,
  52. height: 28.w,
  53. decoration: BoxDecoration(
  54. color: '#FF5555'.color, borderRadius: BorderRadius.circular(100.w)),
  55. child: Center(
  56. child: Row(
  57. mainAxisAlignment: MainAxisAlignment.center,
  58. children: [
  59. Assets.images.iconMessageFriendHelp
  60. .image(width: 12.w, height: 12.w),
  61. SizedBox(width: 2.w),
  62. Text(StringName.newsToContact,
  63. style: TextStyle(fontSize: 13.sp, color: ColorName.white))
  64. ],
  65. ),
  66. ),
  67. ),
  68. );
  69. }
  70. return SizedBox.shrink();
  71. }
  72. // 2:你的好友请求已经被接受
  73. // 3:你的好友请求已经被拒绝
  74. // 4:好友发来的求救
  75. // 5:你的好友删除了你
  76. String getMessageContentTxt(int type) {
  77. if (type == 2) {
  78. return StringName.messageAccepted;
  79. } else if (type == 3) {
  80. return StringName.messageRejected;
  81. } else if (type == 4) {
  82. return StringName.messageTryForHelp;
  83. } else if (type == 5) {
  84. return StringName.messageDeleteYour;
  85. }
  86. return '';
  87. }
  88. // 2:你的好友请求已经被接受
  89. // 3:你的好友请求已经被拒绝
  90. // 4:好友发来的求救
  91. // 5:你的好友删除了你
  92. TextStyle getMessageContentTextStyle(int type) {
  93. if (type == 4) {
  94. return TextStyle(fontSize: 13.sp, color: '#A7A7A7'.color);
  95. }
  96. return TextStyle(fontSize: 13.sp, color: ColorName.black50);
  97. }
  98. Gradient? getMessageBgGradient(int type) {
  99. if (type == 4) {
  100. return LinearGradient(colors: ['#00FF5555'.color, '#38FF5555'.color]);
  101. }
  102. return null;
  103. }
  104. Widget buildMessageItem(ImageProvider avatar,
  105. {required String title,
  106. required String content,
  107. required TextStyle contentTextStyle,
  108. required int createTime,
  109. required Widget statusWidget,
  110. bool? isShowReportButton,
  111. VoidCallback? onReportEvent,
  112. Gradient? bgGradient}) {
  113. return Container(
  114. decoration: BoxDecoration(
  115. color: ColorName.white,
  116. borderRadius: BorderRadius.circular(14.w),
  117. boxShadow: [
  118. BoxShadow(
  119. color: ColorName.black.withOpacity(0.08),
  120. offset: Offset(2, 2),
  121. blurRadius: 10,
  122. )
  123. ]),
  124. margin: EdgeInsets.only(left: 12.w, right: 12.w, bottom: 10.w),
  125. child: Container(
  126. decoration: BoxDecoration(
  127. borderRadius: BorderRadius.circular(14.w),
  128. gradient: bgGradient,
  129. ),
  130. padding: EdgeInsets.symmetric(horizontal: 10.w, vertical: 10.w),
  131. child: Row(
  132. children: [
  133. Image(image: avatar, width: 46.w, height: 46.w),
  134. SizedBox(width: 10.w),
  135. Expanded(
  136. child: Column(
  137. children: [
  138. Row(
  139. children: [
  140. Text(
  141. title,
  142. style: TextStyle(
  143. fontSize: 16.sp,
  144. color: '#202020'.color,
  145. fontWeight: FontWeight.bold),
  146. ),
  147. Spacer(),
  148. Text(
  149. createTime == 0
  150. ? ''
  151. : DateUtil.fromMillisecondsSinceEpoch(
  152. "yyyy-MM-dd HH:mm", createTime),
  153. style: TextStyle(fontSize: 12.sp, color: '#A7A7A7'.color),
  154. )
  155. ],
  156. ),
  157. SizedBox(height: 7.w),
  158. Row(
  159. children: [
  160. Expanded(child: Text(content, style: contentTextStyle)),
  161. SizedBox(width: 16.w),
  162. statusWidget
  163. ],
  164. ),
  165. if (isShowReportButton?? false) Column(
  166. crossAxisAlignment: CrossAxisAlignment.end,
  167. children: [
  168. SizedBox(height: 7.w),
  169. Container(
  170. width: MediaQuery.of(Get.context!).size.width,
  171. alignment: Alignment.centerRight,
  172. child: Container(
  173. width: 100.w,
  174. height: 32.w,
  175. decoration: BoxDecoration(
  176. color: "#7B7DFF".color,
  177. borderRadius: BorderRadius.all(Radius.circular(32.w/2))
  178. ),
  179. alignment: Alignment.center,
  180. //color: Colors.orange,
  181. child: GestureDetector(
  182. onTap: onReportEvent,
  183. child: Container(
  184. child: Text("举报",style: TextStyle(
  185. fontSize: 15.sp,
  186. color: "#FFFFFF".color,
  187. fontWeight: FontWeight.w500
  188. ),
  189. ),
  190. ),
  191. ),
  192. ),
  193. )
  194. ],
  195. )
  196. ],
  197. ))
  198. ],
  199. ),
  200. ),
  201. );
  202. }