fix: 消息页面夜间模式异常 issues #309 | 包含撤回消息时显示异常

This commit is contained in:
guozhigq
2023-12-19 07:47:18 +08:00
parent 6dd1360a76
commit ada1aa5d1d
4 changed files with 108 additions and 81 deletions

View File

@ -70,10 +70,14 @@ class MsgHttp {
});
var res = await Request().get(Api.sessionMsg, data: params);
if (res.data['code'] == 0) {
return {
'status': true,
'data': SessionMsgDataModel.fromJson(res.data['data']),
};
try {
return {
'status': true,
'data': SessionMsgDataModel.fromJson(res.data['data']),
};
} catch (err) {
print(err);
}
} else {
return {
'status': false,

View File

@ -199,7 +199,7 @@ class MessageItem {
int? receiverType;
int? receiverId;
int? msgType;
Map? content;
dynamic content;
int? msgSeqno;
int? timestamp;
List? atUids;
@ -212,7 +212,7 @@ class MessageItem {
senderUid = json['sender_uid'];
receiverType = json['receiver_type'];
receiverId = json['receiver_id'];
// 1 文本 2 图片 18 系统提示 10 系统通知
// 1 文本 2 图片 18 系统提示 10 系统通知 5 撤回的消息
msgType = json['msg_type'];
content = jsonDecode(json['content']);
msgSeqno = json['msg_seqno'];

View File

@ -93,6 +93,9 @@ class _WhisperDetailPageState extends State<WhisperDetailPage> {
future: _futureBuilderFuture,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.data == null) {
return const SizedBox();
}
Map data = snapshot.data as Map;
if (data['status']) {
List messageList = _whisperDetailController.messageList;
@ -138,7 +141,6 @@ class _WhisperDetailPageState extends State<WhisperDetailPage> {
bottom: MediaQuery.of(context).padding.bottom,
),
decoration: BoxDecoration(
color: Colors.white,
border: Border(
top: BorderSide(
width: 4,

View File

@ -15,91 +15,112 @@ class ChatItem extends StatelessWidget {
@override
Widget build(BuildContext context) {
bool isOwner = item.senderUid == 17340771;
bool isPic = item.msgType == 2;
bool isText = item.msgType == 1;
bool isAchive = item.msgType == 11;
bool isArticle = item.msgType == 12;
bool isPic = item.msgType == 2; // 图片
bool isText = item.msgType == 1; // 文本
bool isAchive = item.msgType == 11; // 投稿
bool isArticle = item.msgType == 12; // 专栏
bool isRevoke = item.msgType == 5; // 撤回消息
bool isSystem =
item.msgType == 18 || item.msgType == 10 || item.msgType == 13;
int msgType = item.msgType;
Map content = item.content ?? '';
dynamic content = item.content ?? '';
return isSystem
? (msgType == 10
? SystemNotice(item: item)
: msgType == 13
? SystemNotice2(item: item)
: const SizedBox())
: Row(
children: [
if (!isOwner) const SizedBox(width: 12),
if (isOwner) const Spacer(),
Container(
constraints: const BoxConstraints(
maxWidth: 300.0, // 设置最大宽度为200.0
),
decoration: BoxDecoration(
color: isOwner
? Theme.of(context).colorScheme.primary
: Theme.of(context).colorScheme.secondaryContainer,
borderRadius: BorderRadius.only(
topLeft: const Radius.circular(16),
topRight: const Radius.circular(16),
bottomLeft: Radius.circular(isOwner ? 16 : 6),
bottomRight: Radius.circular(isOwner ? 6 : 16),
),
),
margin: const EdgeInsets.only(top: 12),
padding: EdgeInsets.only(
top: 8,
bottom: 6,
left: isPic ? 8 : 12,
right: isPic ? 8 : 12,
),
child: Column(
crossAxisAlignment: isOwner
? CrossAxisAlignment.end
: CrossAxisAlignment.start,
children: [
isText
? Text(
content['content'],
style: TextStyle(
color: isOwner
? Theme.of(context).colorScheme.onPrimary
: Theme.of(context)
.colorScheme
.onSecondaryContainer),
)
: isPic
? NetworkImgLayer(
width: 220,
height:
220 * content['height'] / content['width'],
src: content['url'],
: isRevoke
? const SizedBox()
: Row(
children: [
if (!isOwner) const SizedBox(width: 12),
if (isOwner) const Spacer(),
Container(
constraints: const BoxConstraints(
maxWidth: 300.0, // 设置最大宽度为200.0
),
decoration: BoxDecoration(
color: isOwner
? Theme.of(context).colorScheme.primary
: Theme.of(context).colorScheme.secondaryContainer,
borderRadius: BorderRadius.only(
topLeft: const Radius.circular(16),
topRight: const Radius.circular(16),
bottomLeft: Radius.circular(isOwner ? 16 : 6),
bottomRight: Radius.circular(isOwner ? 6 : 16),
),
),
margin: const EdgeInsets.only(top: 12),
padding: EdgeInsets.only(
top: 8,
bottom: 6,
left: isPic ? 8 : 12,
right: isPic ? 8 : 12,
),
child: Column(
crossAxisAlignment: isOwner
? CrossAxisAlignment.end
: CrossAxisAlignment.start,
children: [
isText
? Text(
content['content'],
style: TextStyle(
color: isOwner
? Theme.of(context)
.colorScheme
.onPrimary
: Theme.of(context)
.colorScheme
.onSecondaryContainer),
)
: const SizedBox(),
SizedBox(height: isPic ? 7 : 2),
Text(
Utils.dateFormat(item.timestamp),
style: Theme.of(context).textTheme.labelSmall!.copyWith(
color: isOwner
? Theme.of(context)
.colorScheme
.onPrimary
.withOpacity(0.8)
: Theme.of(context)
.colorScheme
.onSecondaryContainer
.withOpacity(0.8)),
)
],
),
),
if (!isOwner) const Spacer(),
if (isOwner) const SizedBox(width: 12),
],
);
: isPic
? NetworkImgLayer(
width: 220,
height: 220 *
content['height'] /
content['width'],
src: content['url'],
)
: const SizedBox(),
SizedBox(height: isPic ? 7 : 2),
Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(
Utils.dateFormat(item.timestamp),
style: Theme.of(context)
.textTheme
.labelSmall!
.copyWith(
color: isOwner
? Theme.of(context)
.colorScheme
.onPrimary
.withOpacity(0.8)
: Theme.of(context)
.colorScheme
.onSecondaryContainer
.withOpacity(0.8)),
),
item.msgStatus == 1
? Text(
' 已撤回',
style:
Theme.of(context).textTheme.labelSmall!,
)
: const SizedBox()
],
)
],
),
),
if (!isOwner) const Spacer(),
if (isOwner) const SizedBox(width: 12),
],
);
}
}