You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
267 lines
9.7 KiB
Dart
267 lines
9.7 KiB
Dart
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 {
|
|
final ChatViewArguments chatViewArguments;
|
|
|
|
const ChatView({super.key, required this.chatViewArguments});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: const CustomAppBar(title: "Chat"),
|
|
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(
|
|
flex: 1,
|
|
child: const Icon(
|
|
Icons.send_rounded,
|
|
color: MyColors.darkPrimaryColor,
|
|
size: 30,
|
|
).onPress(
|
|
() async {
|
|
final status = await chatVM.onTextMessageSend(
|
|
receiverId: chatViewArguments.receiverId,
|
|
message: chatVM.chatMessageText,
|
|
requestId: chatViewArguments.chatTypeEnum == ChatTypeEnum.requestOffer ? chatViewArguments.requestModel!.id : 0,
|
|
offerPrice: "0.0",
|
|
chatMessageType: ChatMessageTypeEnum.freeText,
|
|
);
|
|
|
|
if (status) {
|
|
chatVM.clearChatMessageText();
|
|
}
|
|
},
|
|
),
|
|
)
|
|
],
|
|
).toContainer(isShadowEnabled: true),
|
|
],
|
|
);
|
|
}),
|
|
// body:
|
|
);
|
|
}
|
|
}
|
|
|
|
class ChatMessageCustomWidget extends StatelessWidget {
|
|
final String profileUrl;
|
|
final String senderName;
|
|
final String messageText;
|
|
final ChatMessageTypeEnum messageTypeEnum;
|
|
final RequestOfferStatusEnum requestOfferStatusEnum;
|
|
final bool isSent;
|
|
|
|
const ChatMessageCustomWidget({
|
|
super.key,
|
|
required this.profileUrl,
|
|
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(
|
|
textDirection: isSent ? TextDirection.rtl : TextDirection.ltr,
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Expanded(
|
|
flex: 1,
|
|
child: Image.asset(
|
|
profileUrl,
|
|
width: 34,
|
|
height: 34,
|
|
fit: BoxFit.fill,
|
|
).toCircle(borderRadius: 100),
|
|
),
|
|
10.width,
|
|
Expanded(
|
|
flex: 10,
|
|
child: Column(
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
(isSent ? "You" : senderName).toText(fontSize: 16, isBold: true),
|
|
],
|
|
),
|
|
5.height,
|
|
Column(
|
|
children: [
|
|
Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Expanded(
|
|
child: messageText.toText(
|
|
color: isSent ? MyColors.white : MyColors.lightTextColor,
|
|
fontSize: 12,
|
|
// isBold: true,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
if (messageTypeEnum == ChatMessageTypeEnum.offer) ...[
|
|
buildOfferDetailsInChatMessage(requestOfferStatusEnum: requestOfferStatusEnum),
|
|
],
|
|
],
|
|
).toContainer(
|
|
isShadowEnabled: !isSent,
|
|
backgroundColor: isSent ? MyColors.darkIconColor : MyColors.white,
|
|
borderRadius: 0,
|
|
margin: EdgeInsets.fromLTRB(isSent ? 25 : 0, 0, !isSent ? 25 : 0, 0),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|