|
|
|
|
@ -59,8 +59,17 @@ class _ChatPageState extends State<ChatPage> {
|
|
|
|
|
|
|
|
|
|
void getChatToken() {
|
|
|
|
|
String assigneeEmployeeNumber = Provider.of<ServiceRequestDetailProvider>(context, listen: false).currentWorkOrder?.data?.assignedEmployee?.employeeId ?? "";
|
|
|
|
|
Provider.of<ChatProvider>(context, listen: false).getUserAutoLoginToken(widget.moduleId, widget.requestId, widget.title,
|
|
|
|
|
Provider.of<ServiceRequestDetailProvider>(context, listen: false).currentWorkOrder!.data!.workOrderContactPerson.first.employeeId!, assigneeEmployeeNumber);
|
|
|
|
|
String myEmployeeId = context.userProvider.user!.username!;
|
|
|
|
|
|
|
|
|
|
// String sender = context.settingProvider.username;
|
|
|
|
|
String receiver = context.userProvider.isNurse
|
|
|
|
|
? assigneeEmployeeNumber
|
|
|
|
|
: (context.userProvider.isEngineer ? Provider.of<ServiceRequestDetailProvider>(context, listen: false).currentWorkOrder!.data!.workOrderContactPerson.first.employeeId! : "");
|
|
|
|
|
|
|
|
|
|
// assigneeEmployeeNumber
|
|
|
|
|
|
|
|
|
|
// Provider.of<ChatProvider>(context, listen: false).getUserAutoLoginToken(widget.moduleId, widget.requestId, widget.title, myEmployeeId, assigneeEmployeeNumber);
|
|
|
|
|
Provider.of<ChatProvider>(context, listen: false).getUserAutoLoginToken(widget.moduleId, widget.requestId, widget.title, myEmployeeId, receiver);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
@ -152,21 +161,22 @@ class _ChatPageState extends State<ChatPage> {
|
|
|
|
|
reverse: true,
|
|
|
|
|
itemBuilder: (cxt, index) {
|
|
|
|
|
final currentMessage = chatProvider.chatResponseList[index];
|
|
|
|
|
final bool showSenderName = (index == chatProvider.chatResponseList.length - 1) || (currentMessage.userId != chatProvider.chatResponseList[index + 1].userId);
|
|
|
|
|
bool isSender = chatProvider.chatResponseList[index].userId == chatProvider.sender?.userId!;
|
|
|
|
|
final bool showSenderName =
|
|
|
|
|
(index == chatProvider.chatResponseList.length - 1) || (currentMessage.currentUserId != chatProvider.chatResponseList[index + 1].currentUserId);
|
|
|
|
|
bool isSender = chatProvider.chatResponseList[index].currentUserId == chatProvider.sender?.userId!;
|
|
|
|
|
bool showDateHeader = false;
|
|
|
|
|
if (index == chatProvider.chatResponseList.length - 1) {
|
|
|
|
|
showDateHeader = true;
|
|
|
|
|
} else {
|
|
|
|
|
final nextMessage = chatProvider.chatResponseList[index + 1];
|
|
|
|
|
final currentDate = DateUtils.dateOnly(DateTime.parse(currentMessage.createdAt!));
|
|
|
|
|
final nextDate = DateUtils.dateOnly(DateTime.parse(nextMessage.createdAt!));
|
|
|
|
|
final currentDate = DateUtils.dateOnly(DateTime.parse(currentMessage.createdDate!));
|
|
|
|
|
final nextDate = DateUtils.dateOnly(DateTime.parse(nextMessage.createdDate!));
|
|
|
|
|
if (!currentDate.isAtSameMomentAs(nextDate)) {
|
|
|
|
|
showDateHeader = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return Column(mainAxisSize: MainAxisSize.min, children: [
|
|
|
|
|
if (showDateHeader) dateCard(currentMessage.createdAt?.chatMsgDate ?? ""),
|
|
|
|
|
if (showDateHeader) dateCard(currentMessage.createdDate?.chatMsgDateWithYear ?? ""),
|
|
|
|
|
isSender ? senderMsgCard(showSenderName, chatProvider.chatResponseList[index]) : recipientMsgCard(showSenderName, chatProvider.chatResponseList[index])
|
|
|
|
|
]);
|
|
|
|
|
},
|
|
|
|
|
@ -200,15 +210,6 @@ class _ChatPageState extends State<ChatPage> {
|
|
|
|
|
suffixIconConstraints: const BoxConstraints(),
|
|
|
|
|
hintText: "Type your message here...",
|
|
|
|
|
hintStyle: AppTextStyles.bodyText.copyWith(color: const Color(0xffCCCCCC)),
|
|
|
|
|
// suffixIcon: Row(
|
|
|
|
|
// mainAxisSize: MainAxisSize.min,
|
|
|
|
|
// crossAxisAlignment: CrossAxisAlignment.end,
|
|
|
|
|
// mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
|
// children: [
|
|
|
|
|
//
|
|
|
|
|
// 8.width,
|
|
|
|
|
// ],
|
|
|
|
|
// )
|
|
|
|
|
),
|
|
|
|
|
).expanded,
|
|
|
|
|
IconButton(
|
|
|
|
|
@ -498,12 +499,12 @@ class _ChatPageState extends State<ChatPage> {
|
|
|
|
|
.center;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget senderMsgCard(bool showHeader, ChatResponse? chatResponse, {bool loading = false, String msg = ""}) {
|
|
|
|
|
Widget senderMsgCard(bool showHeader, ChatHistoryResponse? chatResponse, {bool loading = false, String msg = ""}) {
|
|
|
|
|
Widget senderHeader = Row(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
"${chatResponse?.userName ?? "User"}(Me)",
|
|
|
|
|
"${chatResponse?.currentUserName ?? "User"}(Me)",
|
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
|
maxLines: 1,
|
|
|
|
|
style: AppTextStyles.bodyText.copyWith(color: AppColor.neutral50, fontWeight: FontWeight.w600),
|
|
|
|
|
@ -524,44 +525,60 @@ class _ChatPageState extends State<ChatPage> {
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
|
|
|
children: [
|
|
|
|
|
if (showHeader) ...[senderHeader, 4.height] else 8.height,
|
|
|
|
|
Container(
|
|
|
|
|
padding: const EdgeInsets.all(8),
|
|
|
|
|
margin: const EdgeInsets.only(right: 26 + 8, left: 26 + 8),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: loading ? Colors.transparent : AppColor.white10,
|
|
|
|
|
borderRadius: BorderRadius.circular(6),
|
|
|
|
|
Row(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
|
|
|
children: [
|
|
|
|
|
Flexible(
|
|
|
|
|
fit: FlexFit.loose,
|
|
|
|
|
child: Container(
|
|
|
|
|
padding: const EdgeInsets.all(8),
|
|
|
|
|
margin: const EdgeInsets.only(right: 8, left: 26 + 8),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: loading ? Colors.transparent : AppColor.white10,
|
|
|
|
|
borderRadius: BorderRadius.circular(6),
|
|
|
|
|
),
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
chatResponse?.contant ?? msg,
|
|
|
|
|
style: AppTextStyles.bodyText2.copyWith(color: AppColor.neutral120),
|
|
|
|
|
).toShimmer(context: context, isShow: loading),
|
|
|
|
|
if (loading) 4.height,
|
|
|
|
|
Text(
|
|
|
|
|
chatResponse?.createdDate?.chatMsgTime ?? "2:00 PM",
|
|
|
|
|
style: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.neutral50.withOpacity(0.5)),
|
|
|
|
|
).toShimmer(context: context, isShow: loading),
|
|
|
|
|
],
|
|
|
|
|
)),
|
|
|
|
|
),
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
chatResponse?.content ?? msg,
|
|
|
|
|
style: AppTextStyles.bodyText2.copyWith(color: AppColor.neutral120),
|
|
|
|
|
).toShimmer(context: context, isShow: loading),
|
|
|
|
|
if (loading) 4.height,
|
|
|
|
|
Text(
|
|
|
|
|
chatResponse?.createdAt?.chatMsgTime ?? "2:00 PM",
|
|
|
|
|
style: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.neutral50.withOpacity(0.5)),
|
|
|
|
|
).toShimmer(context: context, isShow: loading),
|
|
|
|
|
],
|
|
|
|
|
)),
|
|
|
|
|
if (chatResponse != null)
|
|
|
|
|
if (chatResponse.isSeen!)
|
|
|
|
|
"chat_seen".toSvgAsset(width: 16, height: 16)
|
|
|
|
|
else if (chatResponse.isDelivered!)
|
|
|
|
|
"chat_delivered".toSvgAsset(width: 16, height: 16)
|
|
|
|
|
else
|
|
|
|
|
"chat_sent".toSvgAsset(width: 16, height: 16),
|
|
|
|
|
(26 + 8).width,
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget recipientMsgCard(bool showHeader, ChatResponse? chatResponse, {bool loading = false, String msg = ""}) {
|
|
|
|
|
Widget recipientMsgCard(bool showHeader, ChatHistoryResponse? chatResponse, {bool loading = false, String msg = ""}) {
|
|
|
|
|
String extraSpaces = "";
|
|
|
|
|
int length = 0;
|
|
|
|
|
if ((chatResponse?.content ?? "").isNotEmpty) {
|
|
|
|
|
if (chatResponse!.content!.length < 8) {
|
|
|
|
|
length = 8 - chatResponse.content!.length;
|
|
|
|
|
if ((chatResponse?.contant ?? "").isNotEmpty) {
|
|
|
|
|
if (chatResponse!.contant!.length < 8) {
|
|
|
|
|
length = 8 - chatResponse.contant!.length;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String contentMsg = chatResponse?.content == null ? msg : chatResponse!.content! + extraSpaces;
|
|
|
|
|
print("'$contentMsg'");
|
|
|
|
|
String contentMsg = chatResponse?.contant == null ? msg : chatResponse!.contant! + extraSpaces;
|
|
|
|
|
Widget recipientHeader = Row(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
@ -572,7 +589,7 @@ class _ChatPageState extends State<ChatPage> {
|
|
|
|
|
).toShimmer(context: context, isShow: loading),
|
|
|
|
|
8.width,
|
|
|
|
|
Text(
|
|
|
|
|
chatResponse?.userName ?? "User",
|
|
|
|
|
chatResponse?.currentUserName ?? "User",
|
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
|
maxLines: 1,
|
|
|
|
|
style: AppTextStyles.bodyText.copyWith(color: AppColor.neutral50, fontWeight: FontWeight.w600),
|
|
|
|
|
@ -607,7 +624,7 @@ class _ChatPageState extends State<ChatPage> {
|
|
|
|
|
alignment: Alignment.centerRight,
|
|
|
|
|
widthFactor: 1,
|
|
|
|
|
child: Text(
|
|
|
|
|
chatResponse?.createdAt?.chatMsgTime ?? "2:00 PM",
|
|
|
|
|
chatResponse?.createdDate?.chatMsgTime ?? "2:00 PM",
|
|
|
|
|
style: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.white10),
|
|
|
|
|
),
|
|
|
|
|
).toShimmer(context: context, isShow: loading),
|
|
|
|
|
|