news_list_item.dart 5.5 KB

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