news_list_item.dart 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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.type),
  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(int type) {
  72. if (type == 2) {
  73. return StringName.messageAccepted;
  74. } else if (type == 3) {
  75. return StringName.messageRejected;
  76. } else if (type == 4) {
  77. return StringName.messageTryForHelp;
  78. } else if (type == 5) {
  79. return StringName.messageDeleteYour;
  80. }
  81. return '';
  82. }
  83. // 2:你的好友请求已经被接受
  84. // 3:你的好友请求已经被拒绝
  85. // 4:好友发来的求救
  86. // 5:你的好友删除了你
  87. TextStyle getMessageContentTextStyle(int type) {
  88. if (type == 4) {
  89. return TextStyle(fontSize: 13.sp, color: '#A7A7A7'.color);
  90. }
  91. return TextStyle(fontSize: 13.sp, color: ColorName.black50);
  92. }
  93. Gradient? getMessageBgGradient(int type) {
  94. if (type == 4) {
  95. return LinearGradient(colors: ['#00FF5555'.color, '#38FF5555'.color]);
  96. }
  97. return null;
  98. }
  99. Widget buildMessageItem(ImageProvider avatar,
  100. {required String title,
  101. required String content,
  102. required TextStyle contentTextStyle,
  103. required int createTime,
  104. required Widget statusWidget,
  105. Gradient? bgGradient}) {
  106. return Container(
  107. decoration: BoxDecoration(
  108. color: ColorName.white,
  109. borderRadius: BorderRadius.circular(14.w),
  110. boxShadow: [
  111. BoxShadow(
  112. color: ColorName.black.withOpacity(0.08),
  113. offset: Offset(2, 2),
  114. blurRadius: 10,
  115. )
  116. ]),
  117. margin: EdgeInsets.only(left: 12.w, right: 12.w, bottom: 10.w),
  118. child: Container(
  119. decoration: BoxDecoration(
  120. borderRadius: BorderRadius.circular(14.w),
  121. gradient: bgGradient,
  122. ),
  123. padding: EdgeInsets.symmetric(horizontal: 10.w, vertical: 10.w),
  124. child: Row(
  125. children: [
  126. Image(image: avatar, width: 46.w, height: 46.w),
  127. SizedBox(width: 10.w),
  128. Expanded(
  129. child: Column(
  130. children: [
  131. Row(
  132. children: [
  133. Text(
  134. title,
  135. style: TextStyle(
  136. fontSize: 16.sp,
  137. color: '#202020'.color,
  138. fontWeight: FontWeight.bold),
  139. ),
  140. Spacer(),
  141. Text(
  142. createTime == 0
  143. ? ''
  144. : DateUtil.fromMillisecondsSinceEpoch(
  145. "yyyy-MM-dd HH:mm", createTime),
  146. style: TextStyle(fontSize: 12.sp, color: '#A7A7A7'.color),
  147. )
  148. ],
  149. ),
  150. SizedBox(height: 7.w),
  151. Row(
  152. children: [
  153. Expanded(child: Text(content, style: contentTextStyle)),
  154. SizedBox(width: 16.w),
  155. statusWidget
  156. ],
  157. )
  158. ],
  159. ))
  160. ],
  161. ),
  162. ),
  163. );
  164. }