|
|
@@ -0,0 +1,173 @@
|
|
|
+import 'package:flutter/cupertino.dart';
|
|
|
+import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
+import 'package:location/data/bean/message_info.dart';
|
|
|
+import 'package:location/utils/common_expand.dart';
|
|
|
+
|
|
|
+import '../../resource/assets.gen.dart';
|
|
|
+import '../../resource/colors.gen.dart';
|
|
|
+import '../../resource/string.gen.dart';
|
|
|
+import '../../utils/date_util.dart';
|
|
|
+
|
|
|
+typedef MessageFunCallback = void Function(MessageInfo info);
|
|
|
+
|
|
|
+Widget buildMessageInfoItem(MessageInfo item, MessageFunCallback callback) {
|
|
|
+ return buildMessageItem(Assets.images.iconDefaultFriendAvatar.provider(),
|
|
|
+ title: item.senderPhone ?? '',
|
|
|
+ content: getMessageContentTxt(item),
|
|
|
+ contentTextStyle: getMessageContentTextStyle(item.type),
|
|
|
+ createTime: item.createTime,
|
|
|
+ bgGradient: getMessageBgGradient(item.type),
|
|
|
+ statusWidget: getMessageStatusWidget(item.type, funClick: () {
|
|
|
+ callback(item);
|
|
|
+ }));
|
|
|
+}
|
|
|
+
|
|
|
+// 2:你的好友请求已经被接受
|
|
|
+// 3:你的好友请求已经被拒绝
|
|
|
+// 4:好友发来的求救
|
|
|
+// 5:你的好友删除了你
|
|
|
+Widget getMessageStatusWidget(int type, {VoidCallback? funClick}) {
|
|
|
+ if (type == 2) {
|
|
|
+ return Container(
|
|
|
+ decoration: BoxDecoration(
|
|
|
+ color: '#1F15CB4C'.color, borderRadius: BorderRadius.circular(4.w)),
|
|
|
+ padding: EdgeInsets.symmetric(horizontal: 5.w, vertical: 3.w),
|
|
|
+ child: Text(StringName.newsRequestAgree,
|
|
|
+ style: TextStyle(fontSize: 12.sp, color: '#00BB70'.color, height: 1)),
|
|
|
+ );
|
|
|
+ } else if (type == 3) {
|
|
|
+ return Container(
|
|
|
+ decoration: BoxDecoration(
|
|
|
+ color: '#1FCB1515'.color, borderRadius: BorderRadius.circular(4.w)),
|
|
|
+ padding: EdgeInsets.symmetric(horizontal: 5.w, vertical: 3.w),
|
|
|
+ child: Text(StringName.newsRequestDisagree,
|
|
|
+ style: TextStyle(fontSize: 12.sp, color: '#FF2125'.color, height: 1)),
|
|
|
+ );
|
|
|
+ } else if (type == 4) {
|
|
|
+ return GestureDetector(
|
|
|
+ onTap: funClick,
|
|
|
+ child: Container(
|
|
|
+ width: 79.w,
|
|
|
+ height: 28.w,
|
|
|
+ decoration: BoxDecoration(
|
|
|
+ color: '#FF5555'.color, borderRadius: BorderRadius.circular(100.w)),
|
|
|
+ child: Center(
|
|
|
+ child: Row(
|
|
|
+ mainAxisAlignment: MainAxisAlignment.center,
|
|
|
+ children: [
|
|
|
+ Assets.images.iconMessageFriendHelp
|
|
|
+ .image(width: 12.w, height: 12.w),
|
|
|
+ SizedBox(width: 2.w),
|
|
|
+ Text(StringName.newsToContact,
|
|
|
+ style: TextStyle(fontSize: 13.sp, color: ColorName.white))
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ }
|
|
|
+ return SizedBox.shrink();
|
|
|
+}
|
|
|
+
|
|
|
+// 2:你的好友请求已经被接受
|
|
|
+// 3:你的好友请求已经被拒绝
|
|
|
+// 4:好友发来的求救
|
|
|
+// 5:你的好友删除了你
|
|
|
+String getMessageContentTxt(MessageInfo info) {
|
|
|
+ int type = info.type;
|
|
|
+ if (type == 2) {
|
|
|
+ return StringName.messageAccepted;
|
|
|
+ } else if (type == 3) {
|
|
|
+ return StringName.messageRejected;
|
|
|
+ } else if (type == 4) {
|
|
|
+ return StringName.messageTryForHelp;
|
|
|
+ } else if (type == 5) {
|
|
|
+ return StringName.messageDeleteYour;
|
|
|
+ }
|
|
|
+ return '';
|
|
|
+}
|
|
|
+
|
|
|
+// 2:你的好友请求已经被接受
|
|
|
+// 3:你的好友请求已经被拒绝
|
|
|
+// 4:好友发来的求救
|
|
|
+// 5:你的好友删除了你
|
|
|
+TextStyle getMessageContentTextStyle(int type) {
|
|
|
+ if (type == 4) {
|
|
|
+ return TextStyle(fontSize: 13.sp, color: '#A7A7A7'.color);
|
|
|
+ }
|
|
|
+ return TextStyle(fontSize: 13.sp, color: ColorName.black50);
|
|
|
+}
|
|
|
+
|
|
|
+Gradient? getMessageBgGradient(int type) {
|
|
|
+ if (type == 4) {
|
|
|
+ return LinearGradient(colors: ['#00FF5555'.color, '#38FF5555'.color]);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+}
|
|
|
+
|
|
|
+Widget buildMessageItem(ImageProvider avatar,
|
|
|
+ {required String title,
|
|
|
+ required String content,
|
|
|
+ required TextStyle contentTextStyle,
|
|
|
+ required int createTime,
|
|
|
+ required Widget statusWidget,
|
|
|
+ Gradient? bgGradient}) {
|
|
|
+ return Container(
|
|
|
+ decoration: BoxDecoration(
|
|
|
+ color: ColorName.white,
|
|
|
+ borderRadius: BorderRadius.circular(14.w),
|
|
|
+ boxShadow: [
|
|
|
+ BoxShadow(
|
|
|
+ color: ColorName.black.withOpacity(0.08),
|
|
|
+ offset: Offset(2, 2),
|
|
|
+ blurRadius: 10,
|
|
|
+ )
|
|
|
+ ]),
|
|
|
+ margin: EdgeInsets.only(left: 12.w, right: 12.w, bottom: 10.w),
|
|
|
+ child: Container(
|
|
|
+ decoration: BoxDecoration(
|
|
|
+ borderRadius: BorderRadius.circular(14.w),
|
|
|
+ gradient: bgGradient,
|
|
|
+ ),
|
|
|
+ padding: EdgeInsets.symmetric(horizontal: 10.w, vertical: 10.w),
|
|
|
+ child: Row(
|
|
|
+ children: [
|
|
|
+ Image(image: avatar, width: 46.w, height: 46.w),
|
|
|
+ SizedBox(width: 10.w),
|
|
|
+ Expanded(
|
|
|
+ child: Column(
|
|
|
+ children: [
|
|
|
+ Row(
|
|
|
+ children: [
|
|
|
+ Text(
|
|
|
+ title,
|
|
|
+ style: TextStyle(
|
|
|
+ fontSize: 16.sp,
|
|
|
+ color: '#202020'.color,
|
|
|
+ fontWeight: FontWeight.bold),
|
|
|
+ ),
|
|
|
+ Spacer(),
|
|
|
+ Text(
|
|
|
+ createTime == 0
|
|
|
+ ? ''
|
|
|
+ : DateUtil.fromMillisecondsSinceEpoch(
|
|
|
+ "yyyy-MM-dd HH:mm", createTime),
|
|
|
+ style: TextStyle(fontSize: 12.sp, color: '#A7A7A7'.color),
|
|
|
+ )
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ SizedBox(height: 7.w),
|
|
|
+ Row(
|
|
|
+ children: [
|
|
|
+ Expanded(child: Text(content, style: contentTextStyle)),
|
|
|
+ SizedBox(width: 16.w),
|
|
|
+ statusWidget
|
|
|
+ ],
|
|
|
+ )
|
|
|
+ ],
|
|
|
+ ))
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ );
|
|
|
+}
|