|
|
|
|
@ -1,66 +1,88 @@
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:mc_common_app/classes/consts.dart';
|
|
|
|
|
import 'package:mc_common_app/config/routes.dart';
|
|
|
|
|
import 'package:mc_common_app/extensions/int_extensions.dart';
|
|
|
|
|
import 'package:mc_common_app/extensions/string_extensions.dart';
|
|
|
|
|
import 'package:mc_common_app/models/chat_models/cat_message_model.dart';
|
|
|
|
|
import 'package:mc_common_app/theme/colors.dart';
|
|
|
|
|
import 'package:mc_common_app/utils/enums.dart';
|
|
|
|
|
import 'package:mc_common_app/view_models/chat_view_model.dart';
|
|
|
|
|
import 'package:mc_common_app/widgets/button/show_fill_button.dart';
|
|
|
|
|
import 'package:mc_common_app/widgets/common_widgets/app_bar.dart';
|
|
|
|
|
import 'package:mc_common_app/widgets/extensions/extensions_widget.dart';
|
|
|
|
|
import 'package:mc_common_app/widgets/txt_field.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
|
|
class ChatView extends StatelessWidget {
|
|
|
|
|
const ChatView({super.key});
|
|
|
|
|
final ChatViewArguments chatViewArguments;
|
|
|
|
|
|
|
|
|
|
const ChatView({super.key, required this.chatViewArguments});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Scaffold(
|
|
|
|
|
appBar: const CustomAppBar(title: "Chat"),
|
|
|
|
|
body: Column(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: ListView.separated(
|
|
|
|
|
itemCount: 15,
|
|
|
|
|
separatorBuilder: (BuildContext context, int index) => 20.height,
|
|
|
|
|
itemBuilder: (BuildContext context, int index) {
|
|
|
|
|
return ChatMessageCustomWidget(
|
|
|
|
|
isSent: index.isOdd,
|
|
|
|
|
profileUrl: MyAssets.bnCar,
|
|
|
|
|
messageText: "Hi, How Are you? I can help you out with the desired request.",
|
|
|
|
|
messageTypeEnum: index == 10
|
|
|
|
|
? (MessageTypeEnum.newOfferRequired)
|
|
|
|
|
: index == 12
|
|
|
|
|
? (MessageTypeEnum.offerProvided)
|
|
|
|
|
: (MessageTypeEnum.text),
|
|
|
|
|
senderName: "Al Abdullah Cars",
|
|
|
|
|
);
|
|
|
|
|
}).horPaddingMain(),
|
|
|
|
|
),
|
|
|
|
|
10.width,
|
|
|
|
|
Row(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
flex: 7,
|
|
|
|
|
child: TxtField(
|
|
|
|
|
// value: adVM.vehicleDemandAmount,
|
|
|
|
|
// errorValue: adVM.demandAmountError,
|
|
|
|
|
hint: "Type your message here..",
|
|
|
|
|
keyboardType: TextInputType.text,
|
|
|
|
|
isNeedBorder: false,
|
|
|
|
|
onChanged: (v) => null,
|
|
|
|
|
body: Consumer<ChatVM>(builder: (BuildContext context, ChatVM chatVM, Widget? child) {
|
|
|
|
|
return Column(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: ListView.separated(
|
|
|
|
|
itemCount: chatVM.chatMessages.length,
|
|
|
|
|
separatorBuilder: (BuildContext context, int index) => 20.height,
|
|
|
|
|
itemBuilder: (BuildContext context, int index) {
|
|
|
|
|
ChatMessageModel chatMessageModel = chatVM.chatMessages[index];
|
|
|
|
|
return ChatMessageCustomWidget(
|
|
|
|
|
isSent: chatMessageModel.isMyMessage ?? false,
|
|
|
|
|
profileUrl: MyAssets.bnCar,
|
|
|
|
|
messageText: "${chatMessageModel.message}",
|
|
|
|
|
messageTypeEnum: chatMessageModel.messageTypeEnum ?? ChatMessageTypeEnum.freeText,
|
|
|
|
|
requestOfferStatusEnum:
|
|
|
|
|
(chatMessageModel.requestOffer != null ? chatMessageModel.requestOffer!.requestOfferStatusEnum : RequestOfferStatusEnum.offer) ?? RequestOfferStatusEnum.offer,
|
|
|
|
|
senderName: "${chatMessageModel.senderName}",
|
|
|
|
|
);
|
|
|
|
|
}).horPaddingMain(),
|
|
|
|
|
),
|
|
|
|
|
10.width,
|
|
|
|
|
Row(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
flex: 7,
|
|
|
|
|
child: TxtField(
|
|
|
|
|
value: chatVM.chatMessageText,
|
|
|
|
|
hint: "Type your message here..",
|
|
|
|
|
keyboardType: TextInputType.text,
|
|
|
|
|
isNeedBorder: false,
|
|
|
|
|
onChanged: (v) => chatVM.updateChatMessageText(v),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Expanded(
|
|
|
|
|
Expanded(
|
|
|
|
|
flex: 1,
|
|
|
|
|
child: const Icon(
|
|
|
|
|
Icons.send_rounded,
|
|
|
|
|
color: MyColors.darkPrimaryColor,
|
|
|
|
|
size: 30,
|
|
|
|
|
).onPress(() {}))
|
|
|
|
|
],
|
|
|
|
|
).toContainer(isShadowEnabled: true),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
).onPress(
|
|
|
|
|
() async {
|
|
|
|
|
final status = await chatVM.onTextMessageSend(
|
|
|
|
|
receiverId: "7db5e1ae-6de4-47d7-984b-08db2842f899", //Todo: This should be managed somehow!!
|
|
|
|
|
message: chatVM.chatMessageText,
|
|
|
|
|
requestId: chatViewArguments.chatTypeEnum == ChatTypeEnum.requestOffer ? chatViewArguments.requestModel!.id : 0,
|
|
|
|
|
offerPrice: "0.0",
|
|
|
|
|
chatMessageType: ChatMessageTypeEnum.freeText,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (status) {
|
|
|
|
|
chatVM.updateChatMessageText("");
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
).toContainer(isShadowEnabled: true),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}),
|
|
|
|
|
// body:
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
@ -70,7 +92,8 @@ class ChatMessageCustomWidget extends StatelessWidget {
|
|
|
|
|
final String profileUrl;
|
|
|
|
|
final String senderName;
|
|
|
|
|
final String messageText;
|
|
|
|
|
final MessageTypeEnum messageTypeEnum;
|
|
|
|
|
final ChatMessageTypeEnum messageTypeEnum;
|
|
|
|
|
final RequestOfferStatusEnum requestOfferStatusEnum;
|
|
|
|
|
final bool isSent;
|
|
|
|
|
|
|
|
|
|
const ChatMessageCustomWidget({
|
|
|
|
|
@ -79,9 +102,107 @@ class ChatMessageCustomWidget extends StatelessWidget {
|
|
|
|
|
required this.senderName,
|
|
|
|
|
required this.messageText,
|
|
|
|
|
required this.messageTypeEnum,
|
|
|
|
|
this.requestOfferStatusEnum = RequestOfferStatusEnum.offer,
|
|
|
|
|
required this.isSent,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Widget buildOfferDetailsInChatMessage({required RequestOfferStatusEnum requestOfferStatusEnum}) {
|
|
|
|
|
switch (requestOfferStatusEnum) {
|
|
|
|
|
case RequestOfferStatusEnum.offer:
|
|
|
|
|
return Column(
|
|
|
|
|
children: [
|
|
|
|
|
5.height,
|
|
|
|
|
Row(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
|
|
|
children: [
|
|
|
|
|
"40000".toText(fontSize: 19, isBold: true),
|
|
|
|
|
2.width,
|
|
|
|
|
"SAR".toText(color: MyColors.lightTextColor, height: 2.2, fontSize: 10, isBold: true),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
10.height,
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: ShowFillButton(
|
|
|
|
|
maxHeight: 27,
|
|
|
|
|
title: "Accept",
|
|
|
|
|
fontSize: 9,
|
|
|
|
|
borderColor: MyColors.greenColor,
|
|
|
|
|
isFilled: false,
|
|
|
|
|
onPressed: () {},
|
|
|
|
|
backgroundColor: MyColors.white,
|
|
|
|
|
txtColor: MyColors.greenColor,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
20.width,
|
|
|
|
|
Expanded(
|
|
|
|
|
child: ShowFillButton(
|
|
|
|
|
maxHeight: 27,
|
|
|
|
|
title: "Reject",
|
|
|
|
|
borderColor: MyColors.redColor,
|
|
|
|
|
isFilled: false,
|
|
|
|
|
onPressed: () {},
|
|
|
|
|
backgroundColor: MyColors.white,
|
|
|
|
|
txtColor: MyColors.redColor,
|
|
|
|
|
fontSize: 9,
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
case RequestOfferStatusEnum.negotiate:
|
|
|
|
|
return Column(
|
|
|
|
|
children: [
|
|
|
|
|
Center(
|
|
|
|
|
child: "You asked for the new offer.".toText(
|
|
|
|
|
color: MyColors.adPendingStatusColor,
|
|
|
|
|
fontSize: 12,
|
|
|
|
|
isItalic: true,
|
|
|
|
|
),
|
|
|
|
|
).toContainer(borderRadius: 40, width: double.infinity, backgroundColor: MyColors.adPendingStatusColor.withOpacity(0.16)),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
case RequestOfferStatusEnum.accepted:
|
|
|
|
|
return Column(
|
|
|
|
|
children: [
|
|
|
|
|
Center(
|
|
|
|
|
child: "You have accepted the offer.".toText(
|
|
|
|
|
color: MyColors.adPendingStatusColor,
|
|
|
|
|
fontSize: 12,
|
|
|
|
|
isItalic: true,
|
|
|
|
|
),
|
|
|
|
|
).toContainer(borderRadius: 40, width: double.infinity, backgroundColor: MyColors.adPendingStatusColor.withOpacity(0.16)),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
case RequestOfferStatusEnum.rejected:
|
|
|
|
|
return Column(
|
|
|
|
|
children: [
|
|
|
|
|
Center(
|
|
|
|
|
child: "You have rejected the offer.".toText(
|
|
|
|
|
color: MyColors.adPendingStatusColor,
|
|
|
|
|
fontSize: 12,
|
|
|
|
|
isItalic: true,
|
|
|
|
|
),
|
|
|
|
|
).toContainer(borderRadius: 40, width: double.infinity, backgroundColor: MyColors.adPendingStatusColor.withOpacity(0.16)),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
case RequestOfferStatusEnum.cancel:
|
|
|
|
|
return Column(
|
|
|
|
|
children: [
|
|
|
|
|
Center(
|
|
|
|
|
child: "You have cancelled the offer.".toText(
|
|
|
|
|
color: MyColors.adPendingStatusColor,
|
|
|
|
|
fontSize: 12,
|
|
|
|
|
isItalic: true,
|
|
|
|
|
),
|
|
|
|
|
).toContainer(borderRadius: 40, width: double.infinity, backgroundColor: MyColors.adPendingStatusColor.withOpacity(0.16)),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Directionality(
|
|
|
|
|
@ -125,56 +246,8 @@ class ChatMessageCustomWidget extends StatelessWidget {
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
if (messageTypeEnum == MessageTypeEnum.offerProvided || messageTypeEnum == MessageTypeEnum.newOfferRequired) ...[
|
|
|
|
|
5.height,
|
|
|
|
|
Row(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
|
|
|
children: [
|
|
|
|
|
"40000".toText(fontSize: 19, isBold: true),
|
|
|
|
|
2.width,
|
|
|
|
|
"SAR".toText(color: MyColors.lightTextColor, height: 2.2, fontSize: 10, isBold: true),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
10.height,
|
|
|
|
|
if (messageTypeEnum == MessageTypeEnum.newOfferRequired) ...[
|
|
|
|
|
Center(
|
|
|
|
|
child: "You asked for the new offer.".toText(
|
|
|
|
|
color: MyColors.adPendingStatusColor,
|
|
|
|
|
fontSize: 12,
|
|
|
|
|
isItalic: true,
|
|
|
|
|
),
|
|
|
|
|
).toContainer(borderRadius: 40, width: double.infinity, backgroundColor: MyColors.adPendingStatusColor.withOpacity(0.16)),
|
|
|
|
|
] else ...[
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: ShowFillButton(
|
|
|
|
|
maxHeight: 27,
|
|
|
|
|
title: "Accept",
|
|
|
|
|
fontSize: 9,
|
|
|
|
|
borderColor: MyColors.greenColor,
|
|
|
|
|
isFilled: false,
|
|
|
|
|
onPressed: () {},
|
|
|
|
|
backgroundColor: MyColors.white,
|
|
|
|
|
txtColor: MyColors.greenColor,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
20.width,
|
|
|
|
|
Expanded(
|
|
|
|
|
child: ShowFillButton(
|
|
|
|
|
maxHeight: 27,
|
|
|
|
|
title: "Reject",
|
|
|
|
|
borderColor: MyColors.redColor,
|
|
|
|
|
isFilled: false,
|
|
|
|
|
onPressed: () {},
|
|
|
|
|
backgroundColor: MyColors.white,
|
|
|
|
|
txtColor: MyColors.redColor,
|
|
|
|
|
fontSize: 9,
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
if (messageTypeEnum == ChatMessageTypeEnum.offer) ...[
|
|
|
|
|
buildOfferDetailsInChatMessage(requestOfferStatusEnum: requestOfferStatusEnum),
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
).toContainer(
|
|
|
|
|
@ -191,5 +264,3 @@ class ChatMessageCustomWidget extends StatelessWidget {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum MessageTypeEnum { text, picture, offerProvided, recording, video, newOfferRequired }
|
|
|
|
|
|