|
|
|
|
@ -13,6 +13,8 @@ import 'package:test_sa/new_views/app_style/app_color.dart';
|
|
|
|
|
import 'package:test_sa/new_views/common_widgets/app_filled_button.dart';
|
|
|
|
|
import 'package:test_sa/new_views/common_widgets/default_app_bar.dart';
|
|
|
|
|
|
|
|
|
|
import 'model/user_chat_history_model.dart';
|
|
|
|
|
|
|
|
|
|
enum ChatState { idle, voiceRecordingStarted, voiceRecordingCompleted }
|
|
|
|
|
|
|
|
|
|
class ChatPage extends StatefulWidget {
|
|
|
|
|
@ -105,7 +107,7 @@ class _ChatPageState extends State<ChatPage> {
|
|
|
|
|
child: Row(
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
"Engineer: Mahmoud Shrouf",
|
|
|
|
|
chatProvider.recipient?.userName ?? "",
|
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
|
maxLines: 2,
|
|
|
|
|
style: AppTextStyles.bodyText2.copyWith(color: AppColor.white10),
|
|
|
|
|
@ -123,18 +125,16 @@ class _ChatPageState extends State<ChatPage> {
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Container(
|
|
|
|
|
// width: double.infinity,
|
|
|
|
|
color: AppColor.neutral100,
|
|
|
|
|
child: !chatProvider.userChatHistoryLoading
|
|
|
|
|
child: chatProvider.userChatHistoryLoading
|
|
|
|
|
? ListView(
|
|
|
|
|
padding: const EdgeInsets.all(16),
|
|
|
|
|
children: [
|
|
|
|
|
recipientMsgCard(true, "Please let me know what is the issue? Please let me know what is the issue?", loading: true),
|
|
|
|
|
recipientMsgCard(false, "testing", loading: true),
|
|
|
|
|
recipientMsgCard(false, "testing testing testing", loading: true),
|
|
|
|
|
// dateCard("Mon 27 Oct",),
|
|
|
|
|
senderMsgCard(true, "Please let me know what is the issue? Please let me know what is the issue?", loading: true),
|
|
|
|
|
senderMsgCard(false, "Please let me know what is the issue?", loading: true),
|
|
|
|
|
recipientMsgCard(true, null, msg: "Please let me know what is the issue? Please let me know what is the issue?", loading: true),
|
|
|
|
|
recipientMsgCard(false, null, msg: "testing", loading: true),
|
|
|
|
|
recipientMsgCard(false, null, msg: "testing testing testing", loading: true),
|
|
|
|
|
senderMsgCard(true, null, msg: "Please let me know what is the issue? Please let me know what is the issue?", loading: true),
|
|
|
|
|
senderMsgCard(false, null, msg: "Please let me know what is the issue?", loading: true),
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
: chatProvider.chatResponseList.isEmpty
|
|
|
|
|
@ -145,7 +145,29 @@ class _ChatPageState extends State<ChatPage> {
|
|
|
|
|
style: AppTextStyles.heading6.copyWith(color: AppColor.neutral50.withOpacity(.5), fontWeight: FontWeight.w500),
|
|
|
|
|
).center
|
|
|
|
|
: ListView.builder(
|
|
|
|
|
itemBuilder: (cxt, index) => recipientMsgCard(true, chatProvider.chatResponseList[index].content ?? ""), itemCount: chatProvider.chatResponseList.length))
|
|
|
|
|
padding: const EdgeInsets.all(16),
|
|
|
|
|
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!;
|
|
|
|
|
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!));
|
|
|
|
|
if (!currentDate.isAtSameMomentAs(nextDate)) {
|
|
|
|
|
showDateHeader = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return Column(mainAxisSize: MainAxisSize.min, children: [
|
|
|
|
|
if (showDateHeader) dateCard(currentMessage.createdAt?.chatMsgDate ?? ""),
|
|
|
|
|
isSender ? senderMsgCard(showSenderName, chatProvider.chatResponseList[index]) : recipientMsgCard(showSenderName, chatProvider.chatResponseList[index])
|
|
|
|
|
]);
|
|
|
|
|
},
|
|
|
|
|
itemCount: chatProvider.chatResponseList.length))
|
|
|
|
|
.expanded,
|
|
|
|
|
if (!widget.readOnly) ...[
|
|
|
|
|
Divider(height: 1, thickness: 1, color: const Color(0xff767676).withOpacity(.11)),
|
|
|
|
|
@ -428,6 +450,9 @@ class _ChatPageState extends State<ChatPage> {
|
|
|
|
|
// ),
|
|
|
|
|
|
|
|
|
|
IconButton(
|
|
|
|
|
splashColor: Colors.transparent,
|
|
|
|
|
highlightColor: Colors.transparent,
|
|
|
|
|
hoverColor: Colors.transparent,
|
|
|
|
|
onPressed: () {
|
|
|
|
|
chatProvider.sendTextMessage(textEditingController.text).then((success) {
|
|
|
|
|
if (success) {
|
|
|
|
|
@ -470,12 +495,12 @@ class _ChatPageState extends State<ChatPage> {
|
|
|
|
|
.center;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget senderMsgCard(bool showHeader, String msg, {bool loading = false}) {
|
|
|
|
|
Widget senderMsgCard(bool showHeader, ChatResponse? chatResponse, {bool loading = false, String msg = ""}) {
|
|
|
|
|
Widget senderHeader = Row(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
"Jeniffer Jeniffer Jeniffer(Me)",
|
|
|
|
|
"${chatResponse?.userName ?? "User"}(Me)",
|
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
|
maxLines: 1,
|
|
|
|
|
style: AppTextStyles.bodyText.copyWith(color: AppColor.neutral50, fontWeight: FontWeight.w600),
|
|
|
|
|
@ -484,7 +509,7 @@ class _ChatPageState extends State<ChatPage> {
|
|
|
|
|
Container(
|
|
|
|
|
height: 26,
|
|
|
|
|
width: 26,
|
|
|
|
|
decoration: BoxDecoration(shape: BoxShape.circle, color: Colors.grey),
|
|
|
|
|
decoration: const BoxDecoration(shape: BoxShape.circle, color: Colors.grey),
|
|
|
|
|
).toShimmer(context: context, isShow: loading),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
@ -500,7 +525,7 @@ class _ChatPageState extends State<ChatPage> {
|
|
|
|
|
padding: const EdgeInsets.all(8),
|
|
|
|
|
margin: const EdgeInsets.only(right: 26 + 8, left: 26 + 8),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: AppColor.white10,
|
|
|
|
|
color: loading ? Colors.transparent : AppColor.white10,
|
|
|
|
|
borderRadius: BorderRadius.circular(6),
|
|
|
|
|
),
|
|
|
|
|
child: Column(
|
|
|
|
|
@ -508,11 +533,12 @@ class _ChatPageState extends State<ChatPage> {
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
msg,
|
|
|
|
|
chatResponse?.content ?? msg,
|
|
|
|
|
style: AppTextStyles.bodyText2.copyWith(color: AppColor.neutral120),
|
|
|
|
|
).toShimmer(context: context, isShow: loading),
|
|
|
|
|
if (loading) 4.height,
|
|
|
|
|
Text(
|
|
|
|
|
"2:00 PM",
|
|
|
|
|
chatResponse?.createdAt?.chatMsgTime ?? "2:00 PM",
|
|
|
|
|
style: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.neutral50.withOpacity(0.5)),
|
|
|
|
|
).toShimmer(context: context, isShow: loading),
|
|
|
|
|
],
|
|
|
|
|
@ -522,18 +548,28 @@ class _ChatPageState extends State<ChatPage> {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget recipientMsgCard(bool showHeader, String msg, {bool loading = false}) {
|
|
|
|
|
Widget recipientMsgCard(bool showHeader, ChatResponse? 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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String contentMsg = chatResponse?.content == null ? msg : chatResponse!.content! + extraSpaces;
|
|
|
|
|
print("'$contentMsg'");
|
|
|
|
|
Widget recipientHeader = Row(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
Container(
|
|
|
|
|
height: 26,
|
|
|
|
|
width: 26,
|
|
|
|
|
decoration: BoxDecoration(shape: BoxShape.circle, color: Colors.grey),
|
|
|
|
|
decoration: const BoxDecoration(shape: BoxShape.circle, color: Colors.grey),
|
|
|
|
|
).toShimmer(context: context, isShow: loading),
|
|
|
|
|
8.width,
|
|
|
|
|
Text(
|
|
|
|
|
"Mahmoud Shrouf",
|
|
|
|
|
chatResponse?.userName ?? "User",
|
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
|
maxLines: 1,
|
|
|
|
|
style: AppTextStyles.bodyText.copyWith(color: AppColor.neutral50, fontWeight: FontWeight.w600),
|
|
|
|
|
@ -552,7 +588,7 @@ class _ChatPageState extends State<ChatPage> {
|
|
|
|
|
padding: const EdgeInsets.all(8),
|
|
|
|
|
margin: const EdgeInsets.only(left: 26 + 8, right: 26 + 8),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: AppColor.primary10,
|
|
|
|
|
color: loading ? Colors.transparent : AppColor.primary10,
|
|
|
|
|
borderRadius: BorderRadius.circular(6),
|
|
|
|
|
),
|
|
|
|
|
child: Column(
|
|
|
|
|
@ -560,19 +596,20 @@ class _ChatPageState extends State<ChatPage> {
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
msg,
|
|
|
|
|
contentMsg,
|
|
|
|
|
style: AppTextStyles.bodyText2.copyWith(color: AppColor.white10),
|
|
|
|
|
).toShimmer(context: context, isShow: loading),
|
|
|
|
|
).paddingOnly(end: 6 * length).toShimmer(context: context, isShow: loading),
|
|
|
|
|
if (loading) 4.height,
|
|
|
|
|
Align(
|
|
|
|
|
alignment: Alignment.centerRight,
|
|
|
|
|
widthFactor: 1,
|
|
|
|
|
child: Text(
|
|
|
|
|
"2:00 PM",
|
|
|
|
|
chatResponse?.createdAt?.chatMsgTime ?? "2:00 PM",
|
|
|
|
|
style: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.white10),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
).toShimmer(context: context, isShow: loading),
|
|
|
|
|
],
|
|
|
|
|
).toShimmer(context: context, isShow: loading)),
|
|
|
|
|
)),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|