news_list_item.dart 6.2 KB

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