| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_screenutil/flutter_screenutil.dart';
- import 'package:get/get.dart';
- import 'package:get/get_core/src/get_main.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,{VoidCallback? onReportEvent,bool? isShowReportButton}) {
- return buildMessageItem(Assets.images.iconDefaultFriendAvatar.provider(),
- title: item.senderPhone ?? '',
- content: getMessageContentTxt(item.type),
- contentTextStyle: getMessageContentTextStyle(item.type),
- createTime: item.createTime,
- bgGradient: getMessageBgGradient(item.type),
- onReportEvent: onReportEvent,
- isShowReportButton: isShowReportButton ?? false,
- 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(int 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,
- bool? isShowReportButton,
- VoidCallback? onReportEvent,
- 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
- ],
- ),
- if (isShowReportButton?? false) Column(
- crossAxisAlignment: CrossAxisAlignment.end,
- children: [
- SizedBox(height: 7.w),
- Container(
- width: MediaQuery.of(Get.context!).size.width,
- alignment: Alignment.centerRight,
- child: Container(
- width: 100.w,
- height: 32.w,
- decoration: BoxDecoration(
- color: "#7B7DFF".color,
- borderRadius: BorderRadius.all(Radius.circular(32.w/2))
- ),
- alignment: Alignment.center,
- //color: Colors.orange,
- child: GestureDetector(
- onTap: onReportEvent,
- child: Container(
- child: Text("举报",style: TextStyle(
- fontSize: 15.sp,
- color: "#FFFFFF".color,
- fontWeight: FontWeight.w500
- ),
- ),
- ),
- ),
- ),
- )
- ],
- )
- ],
- ))
- ],
- ),
- ),
- );
- }
|