2023-06-21 17:44:28 +08:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
import 'package:flutter_slidable/flutter_slidable.dart';
|
|
|
|
import 'package:go_router/go_router.dart';
|
2023-08-10 19:08:46 +08:00
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
|
|
|
import 'package:hive_flutter/hive_flutter.dart';
|
2023-06-21 17:44:28 +08:00
|
|
|
|
2024-04-09 17:23:28 +08:00
|
|
|
import '/common/constants.dart';
|
|
|
|
import '/database/box_type.dart';
|
|
|
|
import '/models/contact_model.dart';
|
|
|
|
import '/models/init_get_it.dart';
|
|
|
|
import '/request/server.dart';
|
2023-08-10 19:08:46 +08:00
|
|
|
import 'badge_avatar.dart';
|
2023-06-21 17:44:28 +08:00
|
|
|
|
2023-08-23 16:30:41 +08:00
|
|
|
class FriendChatTile extends StatefulWidget {
|
|
|
|
const FriendChatTile({
|
2023-08-10 19:08:46 +08:00
|
|
|
super.key,
|
|
|
|
required this.contactId,
|
2023-08-11 23:02:31 +08:00
|
|
|
required this.senderId,
|
2023-08-23 16:30:41 +08:00
|
|
|
required this.messageType,
|
2023-08-11 23:02:31 +08:00
|
|
|
required this.text,
|
|
|
|
required this.attachments,
|
|
|
|
required this.dateTime,
|
|
|
|
required this.isShowTime,
|
2023-08-15 10:53:30 +08:00
|
|
|
required this.unreadCount,
|
2023-08-10 19:08:46 +08:00
|
|
|
});
|
|
|
|
|
2023-09-17 17:45:32 +08:00
|
|
|
final int unreadCount;
|
2023-08-23 16:30:41 +08:00
|
|
|
final String contactId, senderId, messageType, text, dateTime;
|
2023-08-11 23:02:31 +08:00
|
|
|
final List<String> attachments;
|
|
|
|
final bool isShowTime;
|
2023-08-10 19:08:46 +08:00
|
|
|
|
|
|
|
@override
|
2023-08-23 16:30:41 +08:00
|
|
|
State<FriendChatTile> createState() => _FriendChatTileState();
|
2023-08-10 19:08:46 +08:00
|
|
|
}
|
|
|
|
|
2023-08-23 16:30:41 +08:00
|
|
|
class _FriendChatTileState extends State<FriendChatTile> {
|
2023-06-21 17:44:28 +08:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-09-17 17:45:32 +08:00
|
|
|
Box<ChatSetting> chatSettingBox = Hive.box<ChatSetting>('chat_setting');
|
|
|
|
ChatSetting chatSetting = chatSettingBox.get(widget.contactId)!;
|
2023-06-21 17:44:28 +08:00
|
|
|
return Slidable(
|
|
|
|
key: const ValueKey(0),
|
|
|
|
endActionPane: ActionPane(
|
|
|
|
motion: const BehindMotion(),
|
|
|
|
dismissible: DismissiblePane(
|
2023-08-11 23:02:31 +08:00
|
|
|
onDismissed: () {
|
|
|
|
chatSetting.isOpen = false;
|
|
|
|
chatSettingBox.put(widget.contactId, chatSetting);
|
|
|
|
},
|
2023-06-21 17:44:28 +08:00
|
|
|
),
|
|
|
|
children: [
|
|
|
|
SlidableAction(
|
|
|
|
onPressed: (BuildContext context) {},
|
|
|
|
backgroundColor: kSecondaryColor,
|
|
|
|
foregroundColor: kContentColorDark,
|
|
|
|
icon: Icons.arrow_upward_rounded,
|
|
|
|
label: '置顶',
|
|
|
|
),
|
|
|
|
SlidableAction(
|
2023-09-17 17:45:32 +08:00
|
|
|
onPressed: (BuildContext context) {
|
|
|
|
chatSetting.isHideMsg = !chatSetting.isHideMsg;
|
|
|
|
chatSettingBox.put(widget.contactId, chatSetting);
|
|
|
|
},
|
2023-06-21 17:44:28 +08:00
|
|
|
foregroundColor: kContentColorDark,
|
|
|
|
backgroundColor: kPrimaryColor,
|
2023-08-10 19:08:46 +08:00
|
|
|
icon: Icons.remove_red_eye,
|
2023-09-17 17:45:32 +08:00
|
|
|
label: chatSetting.isHideMsg ? '显示消息' : '隐藏消息',
|
2023-06-21 17:44:28 +08:00
|
|
|
flex: 1,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
child: ListTile(
|
|
|
|
// Must have a onTap callback or Ink won't work
|
2023-08-23 16:30:41 +08:00
|
|
|
onTap: () {
|
2023-09-09 16:48:47 +08:00
|
|
|
context.pushNamed(
|
2023-08-23 16:30:41 +08:00
|
|
|
'Message',
|
2023-09-09 16:48:47 +08:00
|
|
|
queryParameters: {
|
|
|
|
'friendId': widget.contactId,
|
|
|
|
'type': '0',
|
|
|
|
},
|
2023-08-23 16:30:41 +08:00
|
|
|
);
|
|
|
|
},
|
2023-10-21 21:25:09 +08:00
|
|
|
leading: BadgeAvatar(
|
|
|
|
unreadCount: widget.unreadCount,
|
|
|
|
radius: 25,
|
|
|
|
backgroundImage: CachedNetworkImageProvider(
|
|
|
|
'$userAvatarsUrl/${getIt.get<ContactAccountProfile>().friends[widget.contactId]!.avatar}',
|
|
|
|
),
|
|
|
|
),
|
2023-08-10 19:08:46 +08:00
|
|
|
title: Row(
|
2023-06-21 17:44:28 +08:00
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Expanded(
|
2023-08-10 19:08:46 +08:00
|
|
|
// friend remark or nickname
|
2023-06-21 17:44:28 +08:00
|
|
|
child: Text(
|
2023-08-10 19:08:46 +08:00
|
|
|
getIt
|
|
|
|
.get<Contact>()
|
|
|
|
.friends[widget.contactId]!
|
|
|
|
.friendRemark
|
|
|
|
.isEmpty
|
|
|
|
? getIt
|
|
|
|
.get<ContactAccountProfile>()
|
|
|
|
.friends[widget.contactId]!
|
|
|
|
.nickname
|
|
|
|
: getIt
|
|
|
|
.get<Contact>()
|
|
|
|
.friends[widget.contactId]!
|
|
|
|
.friendRemark,
|
2023-06-21 17:44:28 +08:00
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
),
|
|
|
|
),
|
2023-08-10 19:08:46 +08:00
|
|
|
// latest msg datetime
|
|
|
|
Text(
|
2023-08-11 23:02:31 +08:00
|
|
|
widget.dateTime,
|
2023-08-10 19:08:46 +08:00
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 14,
|
|
|
|
color: kUnActivatedColor,
|
|
|
|
),
|
|
|
|
),
|
2023-06-21 17:44:28 +08:00
|
|
|
],
|
|
|
|
),
|
|
|
|
subtitle: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: Text(
|
2023-08-11 23:02:31 +08:00
|
|
|
widget.text,
|
2023-06-21 17:44:28 +08:00
|
|
|
overflow: TextOverflow.ellipsis,
|
2023-08-10 19:08:46 +08:00
|
|
|
style: const TextStyle(
|
|
|
|
color: kUnActivatedColor,
|
|
|
|
fontSize: 15,
|
|
|
|
),
|
2023-06-21 17:44:28 +08:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|